How many digits does the integer zero have?

Should zero be classified as having no digits, or 1 digit?

Solutions Collecting From Web of "How many digits does the integer zero have?"

Zero ($0$) is part of the modern number system

This system uses the digits $0\cdots9$, and so $0$ is a digit.

Therefore $0$ has $1$ digit.

As noted, the answer depends a lot on what you’re using it for. For writing the number zero out, it clearly has one digit — but for some applications, it’s useful to say that zero has ‘negative infinity’ digits!

How’s that? Well, it’s a theorem that the count of digits in a sum of two (positive, nonzero) numbers is equal to the count of digits in the larger number (possibly plus one), and the count of digits in a product of two (positive, nonzero) numbers is equal to the sum of the count of digits of the two numbers (possibly minus one). For instance, $48$ and $35$ each have two digits, and $48\times35=1680$ has four digits. These results can be derived from the fact that a $d$-digit number $x$ satisfies $10^{d-1}\leq x\lt 10^d$; $d$ is related to the logarithm of $x$ (in fact, it’s $1+\lfloor\log x\rfloor$). For instance, suppose that $x\geq y$, with $x$ a $d$-digit number and $y$ an $f$-digit number (so $d\geq f$); then $10^{d-1}\lt 10^{d-1}+10^{f-1}\leq x+y\leq 10^d+10^f\leq 10^d+10^d=2\cdot 10^d\lt 10^{d+1}$, so $x+y$ must be either $d$ or $d+1$ digits (and it’s easy to see that both can happen).

Now, the same rules can be extended sensibly to allow the numbers to be positive or zero — but only if we define the count of digits of zero to be negative infinity! This makes sense when you consider the inequality that we mentioned; if $0$ had $d$ digits, then logically we must have $10^{d-1}\leq 0$ — but $10^n\gt 0$ for all $n$, so $d$ must be smaller than any number. Likewise, since $0\times x=0$ for all $x$, then if $0$ has $d$ digits it must also have either $d+f-1$ or $d+f$ digits (where $f$ here represents the digit-count of $x$) for all $f$. No real number satisfies this, but if we say that the digit-count of zero is a new number $-\infty$ with the properties that $\max(-\infty, d)=d$ and $(-\infty)+d=-\infty$ for all $d$, then we can maintain the properties of our digit-counting function.

A generalization of this idea shows up in the notion of the degree of a polynomial, where we special-case the zero polynomial in similar fashion and say that it has ‘degree negative infinity’.

In most bases $(b \ne 1)$ it has 1 digit.
$$
(0)_b = (0\cdot b^0)_b = 0
$$
Interesting is what happens in base 1:
$$
(n)_1 = 1^n
$$
e.g. $(2)_1 = 11$ and $(5)_1 = 11111$. It would be tempting to say, it has no digit in base 1:
$$
(0)_1 = \epsilon
$$
where $\epsilon$ is the empty string. But I do not know if it is handled that way.

Note: This article (in German) on the Unary System gives it as example.

Note: See this question and the first answer, second part, as well: What would base 1 be?

Zero is conventionally written as $0$ to avoid confusion. If you saw

$$e^{i\pi}+1=$$

you would think, “Yes, what is the answer? Is it zero or have you forgotten to finish the equation?”.

However, in a computing context, it would be perfectly acceptable to use zero digits for $0$.

Say this was a (line of a) CSV file:

-3,-2,-1,,1,2,3

So long as every field was understood to be a number, the middle one, represented by the empty string, would be read as zero.

In term of storage for computation purposes zero takes the size of a digit. However, the correct answer is probably the number system you are dealing with. I am not sure if there does exist a number system without zero in this modern era but there are several number systems such as binary and decimal number system in which zero is considered as a digit.

I discovered some years ago the base formula says that 0 has 0 digits and had to special case it. The necessity for special casing it suggests that were # digits to come up in a larger problem it might in fact be correct to say 0 has 0 digits.

The given formula for digits in n is floor(log10 |n|) + 1

If we hold that (and we do) 001 = 1, then we may also hold that 000 = 0 and by extension 0 = ” (zero-length string). But allowing zero length strings is nasty for human readers.