How to convert float number to Binary?

前端 未结 6 815
不思量自难忘°
不思量自难忘° 2020-12-07 16:53

Can anyone please tell me how can I convert this float number: 12.25 to binary? I know how to convert the \"12\" but not the 0.25

Any help is much appreciated. Thank

6条回答
  •  一向
    一向 (楼主)
    2020-12-07 17:13

    (d means decimal, b means binary)

    1. 12.25d is your float.
    2. You write 12d in binary and remove it from your float. Only the remainder (.25d) will be left.
    3. You write the dot.
    4. While the remainder (0.25d) is not zero (and/or you want more digits), multiply it with 2 (-> 0.50d), remove and write the digit left of the dot (0), and continue with the new remainder (.50d).

提交回复
热议问题