One integer
If the integer is divided by 2, the quotient is further divided by 2, and 0 is obtained, the remainder is sorted in reverse order.
Take 22 as an example:
22/2 11 + 0
11/2 5 + 1
5/2 2 + 1
2/2 more than 1 0
1/2 more than 0 1
So the binary value of 22 is 10110.
Decimal
Multiply the decimal number by 2, and then the decimal part by 2. Then, the decimal part is rounded up to 0, and the integers are arranged in order.
Take 0.8125 as an example:
0.8125x2 = 1.625 Take an integer of 1. The decimal part is 0.625.
0.625x2 = 1.25Take an integer of 1. The decimal part is 0.25.
0.25x2 = 0.5Take an integer of 0, and the decimal part is 0.5.
0.5x2 = 1.0Integer 1, decimal part is 0, end
Therefore, the binary value of 0.8125 is 0.1101.
An integer with three decimal places
You can directly combine the fractional part and the fractional part to get the sum of the integer and the decimal part.
For example, you can directly combine 22 and 0.8125 to get the value of 22.8125,
So the binary format of 22.8125 is: 10110.1101
Convert decimal to binary