Representation and conversion method of hexadecimal numbers in Python3

Binary representation:

>>> 0b10
2
>>> 0b11
3
>>> 

Octal representation:

>>> 0o11(零哦)
9
>>> 0o10
8
>>> 

Hexadecimal representation:

>>> 0x1f
31
>>> 

Adding nothing in python means decimal.
Convert other hexadecimal numbers to binary, using the bin method

>>> bin(10)
'0b1010'
>>> bin(0o7)
'0b111'
>>> bin(0xE)
'0b1110'
>>> 

Convert other bases to decimal, using int method

>>> int(0b11)
3
>>> int(0o77)
63

Convert other hexadecimal numbers to octal, using oct method

>>> oct(0b111)
'0o7'
>>> oct(0x777)
'0o3567'

Convert hex to hexadecimal, using hex method

>>> hex(888)
'0x378'
>>> hex(0o7777)
'0xfff'
>>> hex(15)
'0xf'
Published 12 original articles · Like1 · Visits 197

Guess you like

Origin blog.csdn.net/qq_39338091/article/details/104882677