In: Computer Science
How do you represent 5.1 (5 + 1/10) in binary? I know that it is 0101. (point something)
The decimal value 5.1 equivalent binary representation is 101.000110011
Explanation:
1) Convert Decimal to Binary first. Convert the decimal 5 into binary that is 101. Below diagram shows how to do that.
2 | 5
--------
2 | 2 - 1
-------
| 1 - 0
------
2) Convert the fraction 0.1 into binary that is . Below steps help to do that.
Binary of 0.1 is .000110011
Step 1
----------
0.1 x 2 = 0.2
Integer = 0
Fraction = 0.2
Since fraction is not equal to 0 so continue doing the same.
Step 2
----------
0.2 x 2 = 0.4
Integer = 0
Fraction = 0.4
Since fraction is not equal to 0 so continue doing the same.
Step 3
----------
0.4 x 2 = 0.8
Integer = 0
Fractional = 0.8
Since fraction is not equal to 0 so continue doing the same.
Step 4
----------
0.8 x 2 = 1.6
Integer = 1
Fractional = 0.6
Since fraction is not equal to 0 so continue doing the same.
Step 5
----------
0.6 x 2 = 1.2
Integer = 1
Fractional = 0.2
Since fraction is not equal to 0 so continue doing the same.
Step 6
----------
0.2 x 2 = 0.4
Integer = 0
Fractional = 0.4
Since fraction is not equal to 0 so continue doing the same.
Step 7
----------
0.4 x 2 = 0.8
Integer = 0
Fractional = 0.8
Since fraction is not equal to 0 so continue doing the same.
Step 8
----------
0.8 x 2 = 1.6
Integer = 1
Fraction = 0.6
Since fraction is not equal to 0 so continue doing the same.
Step 9
----------
0.6 x 2 = 1.2
Integer = 1
Fraction = 0.2
Since fraction is not equal to 0 so continue doing the same.
As this is repeating it will not end, so we can stop here
and have the answer as 0.000110011