One, the conversion between decimal and binary
(1) Decimal conversion to binary, divided into integers and fractional parts
① whole number of parts
Methods: In addition to the 2 method, that is, each time the integer part divided by 2, the remainder is the number of the right, and the quotient continues to divide by 2, the remainder is the number of the last bit, this step continues until the quotient is 0, the last reading, from the last remainder read, until the first remainder. Here are some examples:
Example: Converting a decimal 168 to a binary
The result is that the decimal 168 is converted to binary, (10101000) 2
Analysis: The first step divides 168 by 2, quotient 84, and the remainder to 0.
In the second step, divide quotient 84 by 2 and quotient 42 to 0.
In the third step, divide quotient 42 by 2 and quotient 21 to 0.
The fourth step, divide the quotient 21 by 2, the quotient 10 is 1.
The fifth step, divide the quotient 10 by 2, the quotient 5 is 0.
The sixth step, divide the quotient 5 by 2, the quotient 2 is 1.
The seventh step, divide the quotient 2 by 2, the quotient 1 is 0.
The eighth step, divide the quotient 1 by 2, the quotient 0 is 1.
The Nineth step, reading, because the last one is obtained by dividing the number of times by 2, so it is the highest, reading the numbers from the last remainder to read forward, i.e. 10101000
(2) Number of decimal parts
Method: Multiply the 2 rounding method, the fractional part is multiplied by 2, then take the integer part, the remaining fractional part continues to multiply by 2, then takes the whole number part, the remaining fractional part is multiplied by 2, has been taken to the fractional part
is zero. If you can never be zero, just as the decimal number of rounding, as required to retain how many decimal places, according to the following one is 0 or 1, trade-offs, if it is zero, discard, if it is 1, into a bit. In other words, 0 shekels 1. The readings are to be read from the preceding integers to the following integers, for example:
Example 1: Converting 0.125 to Binary
Result: Convert 0.125 to Binary (0.001) 2
Analysis: The first step, the 0.125 times 2, 0.25, then the whole part of 0, the number of parts divided into 0.25;
The second step, the number of parts 0.25 times 2, 0.5, then the whole part of 0, the number of parts divided into 0.5;
The third step, the number of parts 0.5 times 2, 1.0, then the whole part of 1, the number of parts divided into 0.0;
The fourth step, reading, reads from the first, reading to the last one, that is, 0.001.
Example 2, converting 0.45 to binary (reserved to fourth decimal place)
As you can see from the above steps, when the fifth time we do multiplication, The result is 0.4, then the fractional part continues to multiply by 2, 0.8, 0.8 and multiplied by 2, to 1.6 this has been riding down, the last possible to get a fractional part of zero, so this time had to learn the method of decimal rounding, but the binary system only 0 and 12, so it appears 0 1 into. This is also the computer in the conversion will produce errors, but because of the number of reserved bits, high precision, so it can be ignored.
Well, we can conclude that converting 0.45 to binary restriction equals 0.0111.
The method described above is the conversion of decimal to binary method, it is important to note that:
1) decimal conversion to binary, need to be divided into integers and two parts of the fractional conversion
2) When converting integers, the use of the addition of 2 to the remainder method, and the conversion of decimals, with the use of 2 rounding method
3) Note the direction of their readings
So we can derive from the above method that the decimal number 168.125 is converted to binary 10101000.001, or the decimal number is converted to a binary number of approximately equal to 10101000.0111.
(3) binary conversion to decimal without integer and fractional parts
Methods: By weighted addition method, the number of binary each bit is multiplied by the right, then the sum is the decimal number. Cases
Converts a binary number 101.101 to a decimal number.
Results obtained: (101.101) 2 = (5.625) 10
Everyone in doing binary conversion into decimal need to be aware that
1) to know the weights of each bit in binary
2) to be able to find out the value of each bit
Ii. conversion between binary and octal
First, we need to understand a mathematical relationship, that is, 23=8,24=16, while octal and hex are used in this
Derived from the relationship, that is, a three-bit binary representation of an octal, with a four-bit binary representation of a hexadecimal number.
Next, remember 4 numbers 8, 4, 2, 1 (23=8, 22=4, 21=2, 20=1). Now let's practice the conversion between binary and octal.
(1) binary into octal
Methods: Take the Triad method, that is, from the decimal point of the binary point, to the left (right) every three bits taken into one, and then the three-bit binary by the right to add, the number is a eight-bit binary number, and then, in order to arrange, the position of the decimal point unchanged, the number is the octal number we asked for If you take three bits to the left (right) and take the highest (lowest) bit, if you cannot make up three bits, you can add 0 to the leftmost (rightmost) of the decimal point, the highest bit of the integer (the lowest bit), and fill three bits. Cases
① converting binary number 101110.101 to octal
Get results: Convert 101110.101 to octal to 56.5
② converting binary number 1101.1 to octal
Get results: Convert 1101.1 to octal to 15.4
(2) converting octal into binary
Method: Take a three-way, will be a octal number decomposition into three-bit binary number, with three-bit binary right add to the octal number, the decimal place as usual. Cases:
① converting octal number 67.54 to binary
Therefore, the octal number 67.54 is converted to a binary number of 110111.101100, or 110111.1011
As you can see from the above question, the calculation of the octal binary is converted into binary
First, the octal is expanded from left to right, each bit to three bits, and the decimal position is unchanged.
Then, by each expansion as 22,21,20 (i.e. 4, 2, 1) three bits to do dine, that is ax22+ bx21 +cx20= the number of bits (a=1 or a=0,b=1 or b=0,c=1 or c=0), the ABC arrangement is the binary number of that bit
Next, convert each bit to a binary number in the order listed
Finally, the octal binary is converted into a binary number.
The above method is the binary and octal interchange, you need to pay attention to when doing the problem is
1) The interchange between them is with a three-bit conversion, which differs from binary to decimal conversion
2) When you do add 0 and go to 0, pay attention to the left of the decimal point or the right side of the decimal point (that is, the highest number of integers and decimal places) to add 0 or 0, otherwise it will produce an error
Three or two binary vs. hexadecimal conversions
Method: Similar to binary and octal conversions, is only a (16) and four-bit (binary) conversion, the following specific explanation
(1) binary conversion to hexadecimal
Methods: Take four-in-one method, that is, from the decimal point of the binary to the point, to the left (right) every four bits, and then the four-bit binary right added, the number is a 16-bit binary number, and then, in order, the position of the decimal point is unchanged, the number is the hexadecimal number we ask for. If you take four bits to the left (right) and take the highest (lowest) bit, if you cannot make up four bits, you can add 0 to the leftmost (rightmost) of the decimal point, the highest bit of the integer (the lowest bit), and fill four bits.
① Example: Converting binary 11101001.1011 to hexadecimal
Get results: Convert binary 11101001.1011 to 16 binary to e9.b
② Example: converting 101011.101 to hexadecimal
So get the result: Convert binary 101011.101 to 16 binary to 2B.A
(2) Convert 16 binary to binary
Method: Take a four-way, will be a hexadecimal number decomposition into four-bit binary number, with four-bit binary right add to the hexadecimal number, the decimal place as usual.
① converting hex 6e.2 to binary number
So get the result: Convert the hexadecimal 6e.2 to binary 01101110.0010 or 110110.001
Four or eight binary vs. hexadecimal conversions
Methods: generally cannot be converted directly to each other, generally, octal (or hexadecimal) is converted to binary, and then the binary is converted to 16 (or octal), the decimal place is unchanged. Then the corresponding conversion please refer to the binary and octal conversions above and the binary and hex
Five or eight binary and decimal conversions
(1) Octal into decimal
Methods: By weighted addition method, the number of octet per bit is multiplied by the right, then the sum is the decimal number.
Example: ① converting octal number 67.35 to decimal
(2) Decimal conversion to octal
There are two ways to convert decimal into octal:
1) Indirect method: Convert decimal to binary first, then convert binary into octal
2) Direct method: As we have said before, the octal system is derived from binary, so we can use the decimal conversion to binary similar method, or integer part of the conversion and fractional part of the conversion, the following specific explanation:
① whole number of parts
Methods: In addition to the 8 method, that is, each time the integer part divided by 8, the remainder is the number of the right, and the quotient continues to divide by 8, the remainder is the number of the last bit, this step has been continued until the quotient is 0, the last reading, from the last remainder, up to the front of a remainder.
② small number of parts
Methods: By 8 Rounding method, the fractional part is multiplied by 8, then take the integer part, the remaining fractional part continues to multiply by 8, and then take the integer part, the remainder of the fractional part is multiplied by 8, until the fractional part is zero. If it can never be zero, just as the decimal number of rounding, the provisional name is called 3 4 in.
Example: Converting a decimal number of 796.703125 to an octal number
Solution: First divide this number into integral parts 796 and decimal parts 0.703125
The whole number of parts
Number of decimal parts
Therefore, the resulting decimal 796.703125 conversion octal is 1434.55
The above method can be verified, you can first convert the decimal, and then in the conversion to octal, so as to see whether the same results
66 or 16 binary and decimal conversions
Hexadecimal and octal have a lot of similarities, you can refer to the above octal and decimal conversion itself to try the conversion between the two binary.
With the conversion between the various binaries above, we can refine the previous conversion diagram:
This article introduces the binary, decimal, octal, hexadecimal four of the conversion between each other, you should pay attention to the conversion of the method, as well as the steps, in particular, the decimal conversion period between three kinds of binary, to be divided into integers and fractional parts, and finally the location of the decimal point. But to make sure that there are no mistakes in exams or that you need to practice regularly, it makes perfect.
Conversion between binary, octal, decimal, hexadecimal