For example, with 3 bits, we have
3 2 = 8combinations; namely:
0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1We can interpret these patterns of bits as binary numbers (i.e. numbers in base 2). The binary number system is a positional number system, like decimal, where the value of each digit is either 0 or 1, and the weight is determined by its position in the number. For binary, the weights are powers of 2:
2 1 0 2 2 2 2 1 0 1 0 1 = 1 * 2 + 0 * 2 + 1 * 2 = 5In general, for n bits, we have
n 2combinations which can represent numbers in the range
n [ 2 -1 .. 0]for unsigned numbers or
n-1 n-1 [ +2 -1 .. -2 ]for signed numbers (using a representation called two's compliment).