Calculating bits required to store decimal number

后端 未结 12 828
自闭症患者
自闭症患者 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:54

    The short answer is:

    int nBits = ceil(log2(N));
    

    That's simply because pow(2, nBits) is slightly bigger than N.

提交回复
热议问题