binary to decimal and hexadecimal calculator
(1) convert decimal to binary, divided into integer part and decimal part
① integer part
method: divide by 2 and take the remainder method, that is, divide the integer part by 2 each time, the remainder is the number on the place weight, and the quotient continues to be divided by 2, the remainder is the number on the previous place weight, and this step continues , until the quotient is 0. when reading the last number, read from the last remainder to the first remainder. here's an example:
example: convert decimal 168 to binary
the result is to 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, and the remainder of the quotient 42 is 0.
the third step is to divide the quotient 42 by 2, and the remainder of the quotient 21 is 0.
the fourth step is to divide the quotient 21 by 2, and the remainder of the quotient 10 is 1.
the fifth step is to 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 quotient 2 by 2, and the remainder of quotient 1 is 0.
step 8: divide the quotient 1 by 2, and the remainder of the quotient 0 is 1.
step 9: reading, because the last digit is obtained after dividing by 2 many times, so it is the highest digit. read the number forward from the last remainder, that is, 10101000
(2) decimal part
method: multiply by 2 and round to an integer, that is, multiply the decimal part by 2, then take the integer part, continue to multiply the remaining decimal part by 2, then take the integer part, multiply the remaining decimal part by 2, and take the decimal part. until it reaches zero. if it can never be zero, it is the same as the rounding of decimal numbers. when retaining as many decimal places as required, the number will be rounded based on whether the next digit is 0 or 1. if it is zero, round it off. if it is 1, add one digit. in other words, 0 is rounded to 1. the reading should be read from the previous integer to the following integer. here is an example:
example 1: convert 0.125 to binary to get the result: convert 0.125 to binary (0.001) 2
analysis: in the first step, multiply 0.125 by 2 to get 0.25, then the integer part is 0 and the decimal part is 0.25;
in the second step, 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, starting from the first digit and reading 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 you do the multiplication for the fifth time, the result obtained is 0.4, then the decimal part continues to be multiplied by 2 to get 0.8, 0.8 is multiplied by 2 again, and the multiplication continues until 1.6. in the end, it is impossible. the decimal part is zero. therefore, at this time, we have to learn the decimal method to round, but binary only has two numbers: 0 and 1, so rounding of 0 to 1 occurs. this is also caused by computer errors during conversion, but since there are many reserved digits 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 a method of converting decimal to binary. what you need to pay attention to is:
1) to convert decimal to binary, it needs to be divided into integer and decimal parts and converted separately.
2) when converting an integer, the division by 2 method is used and the remainder method is used. when converting a decimal, the multiplication by 2 method is used.
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 10101000.0111.
(3) binary to decimal conversion does not separate the integer and decimal parts
method: according to the weighted addition method, that is, multiply the binary number by the weight, and then add the sum to the decimal number. example: convert the binary number 101.101 to a decimal number.
the result is: (101.101)2=(5.625)10
what everyone needs to pay attention to when converting binary to decimal
1) to know the weight of each bit of binary
2) to be able to find the value of each bit