How many digits are required to make a byte of information in base $n$?

55 Views Asked by At

Given a base $n$, how can I figure out how many digits are required to hold a byte of data?

For example, a hexadecimal number (base $16$) requires two digits. A binary number (base $2$) requires eight digits.

2

There are 2 best solutions below

0
On BEST ANSWER

A byte can hold $256$ values. $k$ digits in base $b$ can hold $b^k$ values, so you need $b^k=256$ or $k=\log_b(256)=\frac {\ln(256)}{\ln(b)}\approx \frac{5.545}{\ln(b)}$ As fractional digits are hard to come by, you need to round up.

0
On

The way you can work out how many digits of base b is needed to represent 256 possible values (ie an octet) is by using the log function. $\lceil \frac{\log 256}{\log b}\rceil $.