Analysis of syntax and conversion methods for different operating systems in Python
This article describes the syntax and conversion methods of different hexadecimal formats in Python. We will share this with you for your reference. The details are as follows:
Different hexadecimal writing methods
① Octal (Octal) 0o377
② Hex 0xFF
③ Binary 0b111111
Conversion between different hexadecimal values
Python provides three built-in functions that can be used for conversion between different operating systems.
>>> Oct (255), hex (255), bin (255) ('0o377', '0xff ', '0b1111111111 ')
You can also use the int function to convert a string to a value.
>>> Int ('000000'), int ('0xff ', 16) (255)
In addition, you can also use eval, which is similar to the int function, but its parameter is python code.
>>> Eval ('000000'), eval ('0xff ') (255)
Of course, you can also format the Output Using strings.
>>> '{0: 0}, {1: x}, {2: B }'. format (255,255,255) '2014, ff, 255 '>>>' % o, % x, % x' % (11111111) '2014, ff, ff'