7 Binary numbers

In a computer, a binary number has a fixed width. In other words, a binary number has a fixed number of digits. This also means that there is a range of numbers that we can represent for a particular number of binary digits.

Given 16 bits (binary digits, in short), let's figure out the total number of values that can be represented. The quick way is to find out the largest number that can be represented as a 16-bit number. This is rather easy: 1111 1111 1111 1111(2) is the largest binary number with 16 digits. Its hexadecimal representation is ffff(16), and its decimal representation is 65535.

So there are 65535 distinct values that can be represented by a 16-bit number, right?

Close. Although 65535 is the largest value that can be represented by an unsigned binary 16-bit integer, there is a total of 65536 values that can be represented. We missed zero (0)!

Given $n$ bits, we can represent $2^n$ distinct values, and the maximum unsigned value is $2^n-1$. Now, let's figure out whether a 32-bit integer can represent the U.S. deficit in dollars.

Copyright © 2006-08-21 by Tak Auyeung