def bin(s): return str(s) if s<=1 else bin(s>>1) + str(s&1) for example: >>> bin(215) '11010111' Also: >>> 0xd7 215 >>> hex(63) '0x3f >>> print(int('00100001', 2)) 33 >>> print("0x%x" % int('0110110110', 2)) 0x1b6 >>> int('0xff',16) 255 >>> int('01110101', 2) 117 >>> chr(int('01110101', 2)) 'u' >>> ord('u') 117 also: # Python program to convert decimal number into binary, octal and hexadecimal number system # Change this line for a different result dec = 344 print("The decimal value of",dec,"is:") print(bin(dec),"in binary.") print(oct(dec),"in octal.") print(hex(dec),"in hexadecimal.")
See also: