[Python] 进制转换,,python 中除了


python 中除了整型,其他进制的只能用字符串来表示

In [1]: ord(‘A‘)  # 字符 => ASCII码, Return the integer ordinal of a one-character string.Out[1]: 65In [2]: chr(65) # ASCII码 => 字符, Return a string of one character with ordinal i; 0 <= i < 256.Out[2]: ‘A‘In [3]: bin(99) # 十进制 => 二进制, Return the binary representation of an integer or long integer.Out[3]: ‘0b1100011‘In [4]: int(‘0b1100011‘, 2) # 二进制 => 十进制, int(‘1100011‘, 2)Out[4]: 99In [5]: oct(99) # 十进制 => 八进制, Return the octal representation of an integer or long integer.Out[5]: ‘0143‘In [6]: int(‘0143‘, 8) # 八进制 => 十进制Out[6]: 99In [7]: hex(99) # 十进制 => 十六进制, Return the hexadecimal representation of an integer or long integer.Out[7]: ‘0x63‘In [8]: int(‘0x63‘, 16) # 十六进制 => 十进制Out[8]: 99

[Python] 进制转换

评论关闭