Binary, octal, decimal, and hexadecimal are commonly used.
Binary: It is composed of two natural numbers, 0 and 1. The calculation rule is to combine them into one.
Octal ratio: from 0 ~ Seven or eight natural numbers, and the calculation rule is one by one.
Decimal: from 0 ~ 9 is composed of ten natural numbers, and the calculation rule is every ten to one.
Hexadecimal: 0 ~ 9 natural numbers and ~ F is composed of six uppercase letters. Six uppercase letters are 10, 11, 12, 13, 14, and 15, respectively. The rule of operation is to multiply by 16.
In order to better distinguish between various types of hexadecimal, it is usually used for writing to end.
For example, if the decimal number is 2012, the hexadecimal value can be written as (7DC) 16, the octal value can be written as (3734) 8, and the binary value can be written as (011111011100) 2.
Convert decimal to binary
Decimal to binary is divided into integer part and decimal part
The integer part can be divided by 2 to obtain the remainder. The remainder is the number on the bit right, And the quotient obtained is divided by 2. In this cycle, the quotient is 0, and the remainder is read forward.
For example, decimal number 2012
Conversion process
2012/2 = 1006 + 0
1006/2 = 503 + 0
503/2 = 251 + 1
251/2 = 125 + 1
125/2 = 62 + 1
64/2 = 31 + 0
31/2 = more than 15 · 1
15/2 = more than 7 1
7/2 = 3 + 1
3/2 = 1 + 1
1/2 = 0 + 1
The quotient is 0, and the calculation is complete, and the final remainder is read forward, that is, 11111011100
The fractional part can be multiplied by 2 by the fractional part, and then an integer is taken. The remaining decimal part is multiplied by 2, so that the circulation continues until the decimal part is 0. If the decimal part is not 0, according to the requirements, if the next digit is 0, it is optional. If it is 1, then carry 1, and finally read from the integer obtained above.
For example, decimal 0.86
Conversion process
0.86*2 = 1.72 then the integer is 1 decimal point is 0.72
0.72*2 = 1.44 then the integer is 1 decimal point is 0.44
0.44*2 = 0.88 then the integer is 0 decimal 0.88
0.88*2 = 1.76 then the integer is 1 decimal point is 0.76
0.76*2 = 1.52 then the integer is 1 decimal point is 0.52
0.52*2 = 1.04 then the integer is 1 decimal point is 0.04
0.04*2 = 0.08 then the integer is 0 and the decimal point is 0.08
0.08*2 = 0.16 then the integer is 0 and the decimal point is 0.16
0.16*2 = 0.32 then the integer is 0 and the decimal point is 0.32
0.32*2 = 0.64 then the integer is 0 and the decimal point is 0.64
............
Next
The final result is 0.1101110000 ......
Likewise, this is true for decimal to octal and hexadecimal, except for dividing by 8 and 16.
Binary to octal
Three-digit binary represents one octal digit. For example, 2 ^ 3 = 8
The binary to octal conversion can take the decimal point of the binary as the demarcation point. The integer part is taken to the left to take three digits as a unit, the decimal part is taken to the right to take three digits as a unit, and then the three digits are calculated respectively, the calculated result is an octal digit, with the decimal point unchanged. If three digits cannot be raised, the integer part can be supplemented by 0 in the top right (that is, the leftmost part of the integer), and the decimal part is supplemented by 0 in the rightmost part.
For example, binary (11101001.100011) 2
Three digits take one integer part 011 101 001 decimal part 100 011
0*2 ^ 2 + 1*2 ^ 1 + 1*2 ^ 0 = 3 1*2 ^ 2 + 0*2 ^ 1 + 1*2 ^ 0 = 5 0*2 ^ 2 + 0*2 ^ 1 + 1*2 ^ 0 = 1
Therefore, the integer part is 351.
1*2 ^ 2 + 0*2 ^ 1 + 0*2 ^ 0 = 4 0*2 ^ 2 + 1*2 ^ 1 + 1*2 ^ 0 = 3
So the decimal part is 43.
The last octal result is (351.43) 8.
Convert binary to decimal
For the nth hexadecimal notation, the bitwise right of the integer part is N ^ (I-1 ), in the decimal part, the right of the j-digit is N ^ (-j), where I starts with 1.
Sum by right
For example, binary (1011.01) 2
Expand horizontally: 1*2 ^ 3 + 0*2 ^ 2 + 1*2 ^ 1 + 1*2 ^ 0 + 0*2 ^-1 + 1*2 ^-2 = 11.25
Convert binary to hexadecimal
The four-digit binary represents a hexadecimal value, for example, 2 ^ 4 = 16.
The method is similar to binary-to-octal conversion. The difference is that hexadecimal is a unit of four bits.
Example binary (11101001.100011) 2
Four digits take an integer part 1110 1001 decimal part 1000
The final hexadecimal result is (e9.8c) 16.
Octal to binary
Because the octal is from 0 ~ 7 digits, and one octal digit is three binary digits, so you can split one octal digit into three binary digits.
The value corresponding to the binary upper right is the same as this.
2 ^ 7 |
2 ^ 6 |
2 ^ 5 |
2 ^ 4 |
2 ^ 3 |
2 ^ 2 |
2 ^ 1 |
2 ^ 0 |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
Octal binary
0--------000
1--------001
2--------010
3--------011
4--------100
5--------101
6--------110
7--------111
For example, October 25, the obtained binary value is (10101) 2.
Octal 434, And the binary value is (100011100) 2.
Octal to decimal
Sum by right
For example, octal (1011.01) 8
Expand horizontally: 1*8 ^ 3 + 0*8 ^ 2 + 1*8 ^ 1 + 1*8 ^ 0 + 0*8 ^-1 + 1*8 ^-2 = 521.215625
Octal to hexadecimal
Generally, it is not directly converted. It can be converted to binary first. Then convert to the required hexadecimal
Hexadecimal to binary
Because the hexadecimal format is from 0 ~ 9 digits and ~ F is composed of four bits in hexadecimal notation. Therefore, a hexadecimal notation can be split into four bits in binary notation.
Hexadecimal binary
0--------0000
1--------0001
2--------0010
3--------0011
4--------0100
5--------0101
6--------0110
7--------0111
8--------1000
9--------1001
A--------1010
B--------1011
C--------1100
D--------1101
E--------1110
F--------1111
For example, if 9ef is used, the corresponding binary value is 100111101111.
Hexadecimal to decimal
Sum by right, similar to octal to decimal
OK. If there is anything wrong, please make corrections. Thank you!