[Tutor] Is there an easy way to conduct binary numbers?

Juan Shen orion_val at 163.com
Thu Dec 23 13:42:50 CET 2004


I have found there are easy functions and options to do basic octal and
hexadecimal number operation.

oct(...)
oct(number) -> string

Return the octal representation of an integer or long integer.

hex(...)
hex(number) -> string

Return the hexadecimal representation of an integer or long integer.

print '%o' %number
Print a decimal number in octal format.

print '%X' %number
Print a decimal number in hexadecimal format.

However, I can't find their binary counterpart, something like bin(...)
or print '%b'. Binary integer is extremely useful in my
electronic-related job. So...I need help. Is there any function to
transform between binary and decimal integers in python's library? If
not, what's the solution to binary?
Juan



More information about the Tutor mailing list