I have found a few sources which have said that the number of bits in a binary number is equal to


But this doesn't seem to work for binary values less than 1. I would expect the value 0 to have zero bits. But plugging in 0 for n is not in the domain of the function. Stranger results are given by plugging in values like 0.2 which give -2 bits. This doesn't sound right. So I created this equation:


It has the same output as the previous function for all $n>=1$. It even says 0 is 0 bits, and 0.2 is 1 bit, as I would expect.

Why do people seem to like the first function more? Can someone explain why the number of bits in 0 is undefined in terms of Shannon information?


Here are a the sources I drew from:


Given a number, how to find the length of its binary representation?

MathWorld states the first equation is equal to the second, but ignores values less than 1. http://mathworld.wolfram.com/BitLength.html


I'm looking for a strict mathematical explanation for the number of bits in 0 in terms of information theory. The two equations above give different answers, so which is correct and why? To clarify, I don't mean the physical length of '0' or the length of the string that represents '0', but the value zero itself.

According to Mathematica,

"BitLength[n] gives the number of binary bits necessary to represent the integer n"

and executing this command,

BitLength[0] -> 0

but even the Mathematica documentation and MathWorld fail to give a reason for this.

  • 2
    $\begingroup$ NB: $0$ has precisely one bit. $\endgroup$
    – Shaun
    Nov 22 '18 at 2:57
  • 1
    $\begingroup$ Also, please would you link to the sources? $\endgroup$
    – Shaun
    Nov 22 '18 at 2:58
  • 1
    $\begingroup$ @DanielWilliams "a memory bank that contains a '0' is the same as no memory bank at all." That seems very false to me: it contains a $0$, after all. $\endgroup$ Nov 22 '18 at 3:27
  • 3
    $\begingroup$ No, $0$ is a state. There is a difference between $\{0\}$ and $\emptyset=\{\}$. $\endgroup$
    – Shaun
    Nov 22 '18 at 3:30
  • 2
    $\begingroup$ I think there might be a disconnect about what "number of bits" means here. I think the sources are referring to the length of the binary sequence representing the number - certainly this is the case in this source you mentioned - so that e.g. ten has four bits since ten is represented by the string "$1010$." Since zero is represented by "$0$" rather than by the empty string, zero has one bit; meanwhile, non-natural numbers like $0.2$ aren't being talked about here. $\endgroup$ Nov 22 '18 at 3:41

The formulas you quote are for the number of bits in the binary expression of a positive integer. As you say, the first is undefined for $0$ and the second gives $0$ bits. I would say both are wrong for $0$ because it takes one binary digit (note I did not say bit) to express $0$, but those formulas are intended only for positive integers. They agree for all of those.

This is different from the number of bits for $0$ in information theory. In information theory you need to consider the number of possibilities. If you have $256$ equally probable values for a quantity, any one of them is $8$ bits, whether it is $0$ or $234$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.