hexadecimal to decimal
Using the Int () function, the first argument is the string ' 0Xff ', the second argument is the description, and the string is a number of binary numbers. The result of the conversion is a decimal number.
>>> int (' 0xf ', 16)
15
Binary to Decimal
>>> int (' 10100111110 ', 2)
1342
Octal to Decimal
>>> Int (' 17 ', 8)
15
You can actually see that the int () function is used regardless of the number of decimal numbers that are converted into decimals. After that, the second argument is written to clarify that the preceding string is a few decimal digits. Attention must be legal. For example, 2 binary number can not appear 2 such characters.
--------------------------------------------------------------------------------------------------------------- -------------
Decimal Turn hex
>>> Hex (1033)
' 0x409 '
Binary Turn hex
That is, binary first turns into a decimal, and then turns into 16 binary.
>>> Hex (int (' 101010 ', 2))
' 0X2A '
octal to hexadecimal
is octal first turn into decimal, then turn into 16 binary.
>>> Hex (int (' 17 ', 8))
' 0xf '
--------------------------------------------------------------------------------------------------------------- -------------
Decimal Turn binary
>>> Bin (10)
' 0b1010 '
Hex Turn Binary
hexadecimal--decimal--binary
>>> bin (int (' FF ', 16))
' 0b11111111 '
Octal binary to Binary
Octal first to decimal, then to binary
>>> bin (int (' 17 ', 8))
' 0b1111 '
--------------------------------------------------------------------------------------------------------------- -------------
Binary to octal
>>> Oct (0b1010)
' 012 '
Decimal to Octal
>>> Oct (11)
' 013 '
hexadecimal to octal
>>> Oct (0xf)
' 017 '
The OCT function can be seen to convert any number of bytes into a 8-based binary.
Python binary, decimal, 16 binary conversion