py in hex conversion

Other binary conversion to decimal:
a = int("f",16)
print(a)

I.e. directly int, the first parameter is a string, the second parameter is specified hexadecimal

Other binary converted to hexadecimal:
ahex = hex(int("25",8))
print(ahex)
print(type(ahex))

Using the hex function, that is, directly to other binary to decimal first and then to hexadecimal; returns a string

Other hex into binary:
abin = bin(int("25",8))
print(abin)
print(type(abin))

And similar to hexadecimal, with bin function as a transit needs decimal, return the string

Other binary into octal:
aoct=oct(eval("0x15"))
print(aoct)
print(type(aoct))

The octal, then turned directly to the digital input, so the need for a string of words eval function returns a string

Published 29 original articles · won praise 13 · views 2733

Guess you like

Origin blog.csdn.net/zmx2473162621/article/details/103938375