To 十进制
二进制: >>> int('110', 2) -> 6
八进制: >>> int('10', 8) -> 8
十六进制: >>> int('10', 16) -> 16
>>> int('1A', 16) -> 26
To 十六进制:
十进制: >>> hex(12) -> ‘0xc’
二进制: >>> hex(0b100) -> ‘0x4’
八进制: >>> hex(0o11) -> ‘0x9’
To 八进制:
十进制: >>> oct(12) -> ‘014’
二进制: >>> oct(0b100) -> ‘04’
十六进制: >>> oct(0x11) -> ‘021’
To 二进制:
十进制: >>> bin(12) -> '0b1100'
八进制: >>> bin(0o100) -> '0b1000000'
十六进制: >>> bin(0x11) -> '0b10001'
实践一下:
def PowTwoDivider(n):
if(n==0):
return 0
div = 1
while((n & div) == 0):
div = div << 1;
return div
//----------------------------
for x in range(256):
print(bin(x),":",bin(PowTwoDivider(x)) )