Commonly used in the system include: binary, octal, decimal and hexadecimal, they are the difference between the number of operations is a few in a bit.
1. Decimal Turn binary
Command: Bin ()
A = 8print (Bin (a))
Operation Result:
0b1000
Calculation:
binary = decimal decimal + binary
8 1000
8/2 + 0 0 1 0 0 0
4/2 + 0 0 2^3 x1 + 2^2 x0 + 2^1 x0 + 2^0 x 0
2/2 + 0 0
1/2 more than 1
Results: 1000
2. Decimal to Octal
Command: Oct ()
A =print(Oct (a))
Operation Result:
0o22
Calculation:
octal = Decimal decimal = octal
Ditto: 8^1 x 2 + 8^0 x 2
3. Decimal Turn hex
Command: Hex ()
A =print(Hex (a))
Operation Result:
0x26
Calculation:
Hex: 1-9 a-f
decimal = hexadecimal hexadecimal = = Decimal
Ibid.: Ibid.: 16^1 x 2 + 16^0 x 6
38/16 + 6 6
2/16 + 2 2
Results: 26
4. Binary conversion decimal, octal, hex
command: Int ()
A = ' 11100 'print(' decimal:', int (a,2),' octal ', int (b,8), ' hexadecimal ', int (c,16))
Note: The converted variable format is: string format
Operation Result:
Decimal: 288 binary 46,726 binary 69888
5. Character conversion numeric numeric conversion character
Command: Ord () "must be a character" Chr () "must be a number" (Asill code)
# Number = = character (Asill code)A =print(Chr (a))#'n ' Print (Ord (b))
Operation Result:
N110
Python Learning--in-process conversion