Range of Binary Values

For GCSE Computer Science, it's often useful to know the range of numbers that can be represented in binary when using a certain number of bits. This can tell us the number of:

In this sense, despite being described by different terms and/or directions, colour depth, sample size, resolution, bus width and word length essentially describe the same thing - the number of bits used to represent a particular value. But how many different values can those bits represent?

The number of possible values that can be represented in n bits is 2n - e.g. of you are using 8 bits, then the number of different values is 28, or 256. As zero is a possible value, the maximum value is 2n - 1, in the same way that (in Python) for n in range(10) gives us ten values of n, but they are 0 - 9.

It's important to note that using twice as many bits (i.e. doubling the value of n) doesn't give us twice as many values (unless n was 1 to begin with) - each extra bit we add doubles the number of possible values, so while 8 bits can represent 256 different values, 16 bits can represent 65,536 different values (the number of rows in a spreadsheet stored in an .xls file!).

Use the slider below to adjust the number of bits used and see the impact on the number of possible values that can be represented. The slider goes up to 64 because most modern PCs have "64-bit" processors and run "64-bit" operating systems. This means that they have a word length or bus width of 64 bits. Moving the slider to the end will tell you how many different memory locations can be addressed by a 64-bit Memory Address Register (MAR), and moving it to 32 will show you why it's not worth having more than 4Gb RAM in a computer running 32-bit Windows.

Representing a binary number using 8 bits:
21 = 2 possible values in the range
0 - 1.

Number of bits used to represent the number:

What Would That Look Like?

Below you can see the effect of using that number of bits for colour depth and sample size, or the input rows required for the truth table if there were that many inputs to a logic circuit. Each of the squares below is 256px x 256px, so the maximum number of colours displayed is 65,536 and the maximum sample size is 8-bits. Truth tables are shown for up to 28 inputs. Note that modern computers use enough bits to represent photorealistic images and high-quality sound.

Systems that use a smaller number of bits to represent colour usually have a fixed palette of colours rather than using RGB values. The 4-, 8-, 16- and 64-colour palettes shown above come from modes 5 and 2 of the BBC Model B Microcomputer and CGA and EGA modes of PC graphics cards respectively. The original Commodore Amiga had a 32-colour palette, but I couldn't find the codes for those colours.

PS. Whilst making this page I discovered that ordinary JavaScript integers can't represent a number greater than 253 - 1, so I had to use a special type of number called a BigInt and write my own function to calculate the values as Math.pow() doesn't work on BigInts!