Calculating bits required to store decimal number

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

    The formula for the number of binary bits required to store n integers (for example, 0 to n - 1) is:

    loge(n) / loge(2)

    and round up.

    For example, for values -128 to 127 (signed byte) or 0 to 255 (unsigned byte), the number of integers is 256, so n is 256, giving 8 from the above formula.

    For 0 to n, use n + 1 in the above formula (there are n + 1 integers).

    On your calculator, loge may just be labelled log or ln (natural logarithm).

提交回复
热议问题