How many bits are required to represent an integer $ x $ with base $b$?

  • 1
    $\begingroup$ What have you tried, where did you get stuck? $\endgroup$ – orlp Sep 9 '19 at 6:33
  • 2
    $\begingroup$ The number of bits shouldn't depend on the base. $\endgroup$ – Yuval Filmus Sep 9 '19 at 7:22
  • $\begingroup$ I made the question shorter. $\endgroup$ – Xi N Sep 9 '19 at 11:26

You could, if you wanted, encode each digit of the base $b$ representation of an integer in $\lceil \log_2 b \rceil$ bits. This was actually done in the very early days of computing, when binary-coded decimal (BCD) encoding was used to store each digit of the decimal representation of an integer in four bits, from $0000$ for $0$ to $1001$ for $9$.

This somewhat simplifies user input and output (as long as your users always want to work in decimal). The downside is that it makes internal arithmetic more complex, and it wastes memory space. In BCD encoding one byte ($8$ bits) of memory can only store an integer between $0$ and $99$, whereas in binary encoding it can store any integer between $0$ and $255$.

All modern computers store integers internally in binary and do all their internal arithmetic in binary, and convert from or to other bases in their input and output as necessary.

| cite | improve this answer | |

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.