1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Demo of bin(), hex(), double quote, single quote, triple quote, eval print ( '''We will now execute this line: ''' ) print ( '''print("Example: str(), bin(), hex()," +'" double quote,'+" & "+ "' single quote")''' ) print ( "Example: str(), bin(), hex()," + '" double quote,' + " & "+ " ' single quote") print ( "\nInteger to Binary or Hex \n turn integer 255 in to binary 2555:" ) x = 255 print ( str (x) + " becomes " + bin (x)) print ( "\n...or into a hexidecimal string:" ) x = 255 print ( "use hex(x) to find that the hex number 255 is: " , hex (x)) print ( "\nif the number to convert is 4660...." ) print ( "the places in a 4 digit hex number are - left to right in 4660 are 4096s, 256s, 16s, 1s" ) print ( "so Ox1234 means 1 ea 4096's, 2 ea 256's, 3 ea 16's and 4 ea 1's" ) #note use of " and '55 num4660 = "(1*4096) + (2*256) + (3*16) + (4*1)" print (num4660 + " yeilds: " ) print ( eval (num4660)) |