Conversion of various basic types in python, binary, octal, decimal, and hexadecimal
All types in python exist as objects.
In python, there is no char type and only a string type. This may be inconvenient to convert the char type to an integer type, but python already provides these built-in functions for conversion.
In python, except integer types, other hexadecimal types can only be represented by strings.
1 int ()
Convert binary, octal, and hexadecimal to a decimal integer.
>>> Int ('100', 2) 15 >>> int ('F', 16) 15 >>> int ('17', 8) 15
2 chr ()
Converts an integer to a character.
>>> Chr (90) 'Z'
3 ord ()
Converts a character to an integer.
>>> Ord ('Z') 90
4 hex ()
Convert decimal to hexadecimal
>>> Hex (255) '0xff'
5 oct ()
Convert decimal to octal
>>> Oct (255) '123'
6 bin ()
Convert decimal to binary
>>> Bin (255) '0b1111111111'