How many bits does a number need to have, to make it worth using hexadecimal notation of the form 0xHHH...H
over its decimal representation of the form DDD...D
?
Here, "being worth" is defined as "giving a shorter average length for uniformly distributed values in the range $0$ to $2^N-1$", where $N$ is the number of bits. Negative numbers are not considered.
For example, clearly for all $N \ge 64$ it's worth using hexadecimal over decimal, because 18446744073709551615
has length 20, while 0xFFFFFFFFFFFFFFFF
has length 18, and there are many more decimal numbers within the range that are longer than their hexadecimal counterparts than shorter, making it pretty obvious that the decimal lengths in the range where the decimal numbers are shorter don't compensate for the hex gain with greater lengths.
Extra credit for giving solutions to the same problem but with these representations for hexadecimal:
HHH...Hh
(e.g.E5F3h
,3FEh
)DHHH...Hh
(i.e. add leading zero if it starts with a letter, e.g.0E5F3h
,3FEh
)