Explanation: mutual conversion of binary, octal, decimal, and hexadecimal values: in addition to the remainder of 2, the integers are arranged in reverse order, that is, each time an integer is divided by 2, and the remainder is the number on the right, the quotient is divided by 2, and the remainder is the number of the previous right. this step continues until the quotient is 0, and the conversion between the first, decimal and binary is performed at the final reading.
(1) convert decimal to binary, divided into integer part and decimal part
① Integer
Method: divide the remainder by 2 and sort them in reverse order, that is, divide the integer part by 2 each time, and the remainder is the number on the bit right, while the operator is divided by 2, the remainder is the number on the previous right. this step continues until the quotient is 0 and the last read starts from the last remainder until the first remainder. The following is an example:
For example, convert decimal 168 to binary
The result is as follows: Convert decimal 168 to binary (10101000)
Step 1: divide 168 by 2, the quotient 84, and the remainder is 0.
Step 2: divide quotient 84 by 2, and the remainder of quotient 42 is 0.
Step 3: divide quotient 42 by 2, and the remainder of quotient 21 is 0.
Step 4: divide quotient 21 by 2, and the remainder of quotient 10 is 1.
Step 5: divide quotient 10 by 2, and the remainder of quotient 5 is 0.
Step 6: divide quotient 5 by 2, and the remainder of quotient 2 is 1.
Step 7: divide quotient 2 by 2, and the remainder of quotient 1 is 0.
Step 8: divide quotient 1 by 2, and the remainder of quotient 0 is 1.
Step 9: read the data. because the last digit is obtained after multiple times divided by 2, it is the highest bit. read the number from the remainder, that is, 10101000.
(2) decimal part
Method: multiply the decimal part by 2, and then take the integer part. multiply the remaining decimal part by 2, and then take the integer part, the remaining decimal part is multiplied by 2, and the fractional part is obtained all the time.
Zero. If the value cannot be zero, the number of decimal places is rounded to the nearest decimal point. if the number of decimal places is retained as required, the value is 0 or 1. if the value is zero, the value is discarded, if it is 1, it is directed to the first digit. In other words, it means 0 homes and 1 homes. The reading should read the following integer from the front integer. the following example shows:
Example 1: convert 0.125 to binary
Result: convert 0.125 to binary (0.001) 2.
Analysis: In the first step, multiply 0.125 by 2 and get 0.25, the integer part is 0, and the decimal part is 0.25;
Step 2: multiply the decimal part 0.25 by 2 and get 0.5. the integer part is 0 and the decimal part is 0.5;
Step 3: multiply the decimal part 0.5 by 2. if the decimal part is 1.0, the integer part is 1 and the decimal part is 0.0;
Step 4: read the data, starting from the first reading, and reading the last one, that is, 0.001.
Example 2: convert 0.45 to binary (retain the fourth decimal point)
As you can see from the above steps, when the fifth multiplication is performed, the result is 0.4. then, multiply the decimal part by 2, and multiply the decimal part by 0.8, 0.8, and 2, in this way, the decimal part is not allowed to be zero. Therefore, we have to study the decimal method to rounding the decimal part, but the binary value is only 0 and 1, as a result, "0 homes and 1" appear. This is also an error generated by the computer during conversion, but it is negligible due to the large number of reserved digits and high accuracy.
Then, we can obtain the result of converting 0.45 to a binary value of approximately 0.0111.
The method described above is to convert decimal to binary. Note the following:
1) convert decimal to binary, which must be divided into two parts: integer and decimal.
2) when the integer is converted, the remainder method except 2 is used. when the decimal number is converted, the integer is rounded up by 2.
3) pay attention to their reading direction
Therefore, from the above method, we can obtain that the decimal number 168.125 is converted to the binary number 10101000.001, or the decimal number is converted to the binary number about 10101000.0111.
(3) convert binary data to decimal data, regardless of integer or decimal data.
Method: multiply the number on each binary by the right by the weighted addition method, and the sum of the values is the decimal number. Example
Converts 101.101 binary to decimal.
Result: (101.101) 2 = (5.625) 10
Note the following when converting binary to decimal:
1) Know the weights of each binary object.
2) You must be able to find each value.
II. conversion between binary and octal
First, we need to understand a mathematical relationship, that is, 23 = 8, 24 = 16, while octal and hexadecimal use this
Derived from the relationship, that is, the three-digit binary represents an octal, and the four-digit binary represents a hexadecimal number.
Remember four numbers 8, 4, 2, and 1 (23 = 8, 22 = 4, 21 = 2, 20 = 1 ). Now let's practice the conversion between binary and octal.
(1) binary conversion to octal
Method: use the three-in-one method, that is, to take one decimal point from the binary to the demarcation point, to the left (to the right), and then add the three binary values to the weights, the obtained number is an eight-bit binary number, which is arranged in sequence and the decimal point remains unchanged. the obtained number is the required octal number. If three digits are taken to the left (to the right) and the highest (lowest) digits are obtained, you can add three digits to the left (rightmost) of the decimal point, that is, the highest (lowest) digit of the integer) add 0 to three digits. Example
① Convert the binary number 101110.101 to octal
Expected result: convert 101110.101 to 56.5
② Convert binary 1101.1 to octal
Expected result: convert 1101.1 to 15.4
(2) convert octal to binary
Method: Take the decimal three Method to divide an octal number into three binary numbers. use the three binary values to add the octal numbers according to the weights. the decimal point remains the same. Example:
① Convert octal 67.54 to binary
Therefore, convert octal 67.54 to binary 110111.101100, that is, 110111.1011
As you can see from the above question, convert octal to binary.
First, split the octal sequence from left to right. each member is expanded to three digits, and the decimal point remains unchanged.
Then, we expand to, 21, 20 (4, 2, and 1) each person to calculate the number, that is, the number of a x 22 + B x 21 + c x 20 = the bit (a = 1 or a = 0, B = 1 or B = 0, c = 1 or c = 0). sort abc as the binary number of the bit.
Next, convert each part to a binary number in order.
Finally, we get a binary number converted from octal.
The above method is the interchange between binary and gossip. when you are doing the question, you must note that
1) the interchange between them is a one-and three-digit conversion, which is different from binary and decimal conversion.
2) when adding 0 and removing 0, you should note that it is at the leftmost of the decimal point or rightmost of the decimal point (that is, the highest digit of the integer and the lowest digit of the decimal point) 0 or 0. Otherwise, an error occurs.
III. binary and hexadecimal conversion
Method: similar to binary and octal conversion, it is only a conversion of one (16) and four (binary ).
(1) convert binary to hexadecimal
Method: use the four-in-one method, that is, the decimal point of the binary is the demarcation point, and each four digits to the left (to the right) are taken as one digit, and then the four binary values are weighted together, the resulting number is a sixteen-bit binary number, which is arranged in sequence and the decimal point remains unchanged. the obtained number is the hexadecimal number we want. If four digits are left (to the right) and the highest (lowest) digits are obtained, you can add four digits to the left (to the right) of the decimal point ), that is, to add 0 to the highest digit of an integer.
Example 1: Convert binary 11101001.1011 to hexadecimal
Expected result: Convert binary 11101001.1011 to hexadecimal format E9. B.
② Example: convert 101011.101 to hexadecimal
The result is as follows: Convert binary 101011.101 to hexadecimal 2B..
(2) Convert hexadecimal to binary
Method: Take the decimal four Method to divide a hexadecimal number into four binary numbers. use the four binary values to add the hexadecimal number according to the weights. the decimal point remains the same.
① Convert hexadecimal 6E. 2 to binary
Therefore, the expected result is as follows: convert the hexadecimal 6E. 2 to binary 01101110.0010 or 110110.001.
IV. conversion between octal and hexadecimal
Method: Generally, they cannot be directly converted from octal (or hexadecimal) to binary, and then convert the binary to hexadecimal (or octal) without changing the decimal point. For the conversion, refer to the preceding binary and octal conversion and binary and hexadecimal conversion.
V. conversion between octal and decimal
(1) convert octal to decimal
Method: Add weights to multiply the number of each person on the octal node by the bitwise, and then add the sum of the values in decimal format.
Example: ① convert octal decimal number 67.35
(2) convert decimal to octal
There are two methods to convert decimal to octal:
1) indirect method: Convert decimal to binary, and then convert binary to octal.
2) Direct method: As we have mentioned earlier, Octal is derived from binary, so we can use a method similar to decimal conversion to binary, or integer and decimal conversion, the following is a detailed explanation:
① Integer
Method: divide the integer part by 8 by the remainder method, and the remainder is the number of the bit permission. the quotient is divided by 8, the remainder is the number on the previous right. this step continues until the quotient is 0 and starts from the last remainder at the last reading until the first remainder.
② Fractional part
Method: multiply the decimal part by 8, then take the integer part, multiply the remaining decimal part by 8, then take the integer part, and multiply the remaining decimal part by 8, until the fractional part is zero. If it cannot be zero, it is rounded to the nearest decimal number.
For example, convert the decimal number 796.703125 to the octal number.
Solution: divide the number into integer part 796 and decimal part 0.703125.
Integer
Decimal part
Therefore, we can convert the decimal value to 796.703125 in octal format.
The above method can be verified, you can first convert the decimal number, and then convert it to octal, to see if the results are the same
VI. hexadecimal and decimal conversion
There are many similarities between hexadecimal and octal. you can refer to the above octal and decimal conversion to try the conversion between these two hexadecimal.
Through the above conversions between various hexadecimal types, we can reimprove the previous conversion diagram:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.