Integer part and fraction part of the number are separated
- Divide the integer by 2
- Get the remainder
- Repeat until the quotient is 0
- Reverse the order of the remainders
i ÷ 2 = q
|
i % 2 = r
|
|
Integer Part: 0
Converts the integer part of the number to binary
- Multiply the fraction by 2: f × 2
- Get the integer part of the result: int(r)
- In the next step use the fraction part of the result: f = r - int(r)
- Repeat while the fraction part is not 0: f ≠ 0
- Use the integers in the order they were obtained
Fraction Part: 0
Converts the fraction part of the number to binary
- Concatenate the integer and fraction parts
- Truncate the result to the desired precision
- Pad the result with 0s to the desired precision
Binary: 0.0
Concatenates the integer and fraction parts of the number