Binary, octal, and hexadecimal conversions are all very easy, that is, "add by weight."
The so-called "right" is also the "right". For example, the decimal 1th bit is0= 1, the 2nd bit is1= 10, the position of the 3rd bit is2= 100, and the bit right of the binary 1th bit is 20= 1, and the bit right of the 2nd bit is 2 1= 2, the 3rd bit right is 22= 4. To set the number to use N (cardinality is also N), then the bit right of the first bit is N(i-1).
Different binary conversions to decimal examples:
Binary: 1001 = 1x23 + 0x22+ 0x21 + 1x20 = 8 + 0 + 0 + 1 = 9
Binary: 101.1001 = 1x22 + 0x21+ 1x20+ 1x2-1+ 0x2-2 + 0x2-3 + 1x2-4= 4 + 0 + 1 + 0.5 + 0 + 0 + 0.0625 = 5.5625
Octal: 0302 = 3x82 + 0x81+ 2x80 = 192 + 0 + 2 = 194
Octal: 0302.46 = 3x82 + 0x81 + 2x80 + 4x8-1 + 6x8-2 = 192 + 0 + 2 + 0. 5 + 0.09375 = 194.59375
Hex: 0xea7 = 14x162 + 10x161 + 7x160= 3751
Decimal conversion to binary--rolling division
The table in the previous section gives a simple decimal and binary conversion relationship, and you can use rolling to get more conversion relationships. Rolling division is the method of "addition of modulus". In addition to modulo is the number of a few into the other into the system, the other is the base of the model, with the number of the transformation will be transformed by the modulo, take its remainder.
The following illustration takes the decimal "19" conversion to binary for an example:
As shown in the figure, divide by 2, until the quotient is 0, and the remainder is the binary number of the obtained.
Note: The remainder is arranged in reverse order, that is, the remainder of the first is sorted at the last side of the binary, and the remainder in the last order is ranked at the top of the binary. in the example above, the last binary number obtained is 10011.
Although other systems can also be converted according to the rolling division, it is more cumbersome to introduce a simpler approach.
Conversion of binary and octal systems
Binary to octal conversion is a three-digit binary number converted to a octal number, the order of operations from low to high, in turn, the high point of less than three in 0 supplement. Take binary "1011101" as an example, as shown in the following illustration:
The result of the conversion is: 1011101 = 0135
The idea of octal to binary conversion is an octal three-bit conversion to binary, and the order of operations is from low to high. Also take octal "0135" as an example, as shown in the following illustration:
The result of the conversion is: 0135 = 1011101
Binary and hexadecimal conversions
Binary to 16 conversion, four-bit converted into a 16-in-one, the order of operations from low to high, in turn, the high point of less than four bits with zero complement. For example, convert "1110011" to 16, as shown in the following illustration:
The result of the conversion is: 1001011101 = 0x25d
Hexadecimal converts to binary, which converts the hexadecimal one to a binary four-bit, noting that the order of operations is performed sequentially from low to high. Also, take the hexadecimal "0x25d" as an example, as shown in the following illustration:
The above is the C language into direct conversion to do a data collation, learning to convert the friend can refer to the