Calculating bits required to store decimal number

后端 未结 12 790
自闭症患者
自闭症患者 2020-12-23 22:21

This is a homework question that I am stuck with.

Consider unsigned integer representation. How many bits will be required to store a decimal number

12条回答
  •  暖寄归人
    2020-12-23 22:55

    This one works!

    floor(loge(n) / loge(2)) + 1
    

    To include negative numbers, you can add an extra bit to specify the sign.

    floor(loge(abs(n)) / loge(2)) + 2
    

提交回复
热议问题