Decimal to Binary and Hexadecimal Calculator
(1) Decimal to binary conversion, divided into integer part and decimal part
① Integer part
Method: Divide by 2 and take remainder method, that is, each time the integer part is divided by 2, the remainder is the number on the position, and the quotient is divided by 2 again, the remainder is the number on the previous position, this step continues until the quotient is 0, and the last reading is from the last remainder to the first remainder. The following is an example:
Example: Convert decimal 168 to binary
Result Convert decimal 168 to binary, (10101000)2
Analysis: The first step is to divide 168 by 2, the quotient is 84, and the remainder is 0.
The second step is to divide the quotient 84 by 2, the quotient is 42 and the remainder is 0.
Step 3: Divide the quotient 42 by 2, and the remainder of the quotient 21 is 0.
Step 4: Divide the quotient 21 by 2, and the remainder of the quotient 10 is 1.
Step 5: Divide the quotient 10 by 2, and the remainder of the quotient 5 is 0.
Step 6: Divide the quotient 5 by 2, and the remainder of the quotient 2 is 1.
Step 7: Divide the quotient 2 by 2, and the remainder of the quotient 1 is 0.
Step 8: Divide the quotient 1 by 2, and the remainder of the quotient 0 is 1.
Step 9: Read the number. Since the last digit is obtained by dividing by 2 multiple times, it is the highest digit. Read the number from the last remainder forward, i.e. 10101000
(2) Decimal part
Method: Multiply by 2 and round up. That is, multiply the decimal part by 2, then take the integer part, multiply the remaining decimal part by 2 again, then take the integer part, and multiply the remaining decimal part by 2 again until the decimal part is zero. If it can never be zero, it is the same as rounding a decimal number. When the number of decimal places required is kept, it is determined according to whether the next digit is 0 or 1. If it is zero, it is discarded. If it is 1, it is rounded up. In other words, 0 is rounded up and 1 is rounded up. The readings should be read from the first integer to the last integer. Here is an example:
Example 1: Convert 0.125 to binary. The result is: Convert 0.125 to binary (0.001)2
Analysis: The first step is to multiply 0.125 by 2 to get 0.25, then the integer part is 0 and the decimal part is 0.25;
The second step is to multiply the decimal part 0.25 by 2 to get 0.5, then the integer part is 0 and the decimal part is 0.5;
The third step is to multiply the decimal part 0.5 by 2 to get 1.0, then the integer part is 1 and the decimal part is 0.0;
The fourth step is to read the number from the first digit to the last digit, which is 0.001.
Example 2: Convert 0.45 to binary (retain to the fourth decimal place)
As you can see from the above steps, when the fifth multiplication is done, the result is 0.4, then the decimal part is multiplied by 2 to get 0.8, 0.8 is multiplied by 2 again, and it is impossible to get a zero decimal part in the end. Therefore, at this time, we have to learn the decimal method to round off, but there are only two binary numbers, 0 and 1, so 0 is rounded to 1. This is also an error in the conversion of the computer, but because there are many digits retained and the accuracy is very high, it can be ignored.
Then, we can conclude that converting 0.45 to binary is approximately equal to 0.0111
The method introduced above is the method of converting decimal to binary. What you need to pay attention to is:
1) When converting decimal to binary, you need to divide it into two parts, integer and decimal, and convert them separately
2) When converting integers, use the remainder method of division by 2, and when converting decimals, use the multiplication by 2 method
3) Pay attention to their reading direction
Therefore, from the above method, we can conclude that the decimal number 168.125 converted to binary is 10101000.001, or the decimal number converted to binary is approximately equal to 1010100.0111.
(3) Convert binary to decimal without distinguishing integers and decimal parts
Method: According to the weighted addition method, multiply the number on each binary digit by the weight, and then add the sum to get the decimal number. For example, convert the binary number 101.101 to a decimal number.
The result is: (101.101)2=(5.625)10
What you need to pay attention to when converting binary to decimal is
1) Know the weight of each binary digit
2) Be able to find the value of each digit