Everything a computer stores is held as binary digits. This topic covers number bases, how text, images and sound are represented, and how files are made smaller.
Three bases are used: decimal (base 10), binary (base 2) and hexadecimal (base 16).
Binary uses the digits 0 and 1. Hexadecimal uses 0 to 9 and then A to F for the values ten to fifteen.
A circuit can hold one of two stable states, on or off, reliably and cheaply. Those two states map directly onto the digits 1 and 0, so all data is stored in binary.
Each binary column has a place value: 1, 2, 4, 8, 16, 32, 64, 128 reading right to left. Add the place values of the columns holding a 1.
The largest value 8 bits can hold is 255.
Work from the largest place value down. Take each place value if it fits within what is left, and write 1; otherwise write 0.
Each hexadecimal digit is exactly four binary digits, so conversion works in groups of four. 1111 is F, and 1010 is A.
To reach decimal, multiply the first hexadecimal digit by 16 and add the second.
Hexadecimal writes a long binary pattern in a quarter of the space, and converts back exactly. It is easier for people to read and to copy without error.
A bit is a single 0 or 1. Four bits are a nibble and eight bits are a byte.
Larger units go up in thousands: kilobyte, megabyte, gigabyte, terabyte.
Add column by column from the right. 1 + 1 gives 0 and carries 1 into the next column; 1 + 1 + 1 gives 1 and carries 1.
Overflow happens when a result needs more bits than are available. The extra bit is lost and the stored answer is wrong.
A logical shift moves every bit left or right, filling the empty positions with 0.
A shift of one place to the left doubles an unsigned value; a shift right halves it, discarding anything shifted off the end.
A character set is an agreed list of characters and the binary code that stands for each one. Without a shared set, one machine cannot read another’s text.
Standard ASCII uses 7 bits per character, giving 128 codes, which covers English but little else.
Unicode uses more bits per character and covers the writing systems of the world, including symbols and emoji. The cost is a larger file for the same text.
A bitmap image is a grid of pixels. Each pixel is stored as a binary value standing for its colour.
Resolution is the number of pixels, usually given as width by height. Colour depth is the number of bits used per pixel.
A colour depth of n bits allows 2 to the power n colours, so 2 bits give 4 colours and 8 bits give 256. Raising either raises both quality and file size.
File size in bits is width × height × colour depth. Dividing by 8 converts to bytes.
Sound is analogue. To store it, the height of the wave is measured at regular intervals, and each measurement is stored as a binary number. This is sampling.
The sample rate is how many samples are taken each second, measured in hertz. The sample resolution is the number of bits per sample.
Raising either gives a closer copy of the original and a larger file.
File size in bits is sample rate × sample resolution × duration in seconds. Multiply by the number of channels for stereo.
Each sample is rounded to the nearest level the available bits allow, and nothing is recorded between samples. A digital copy is therefore an approximation of the original, however close.
Compression makes a file smaller, so it takes less storage, transfers faster and uses less bandwidth.
Lossy compression permanently discards some data. The file is much smaller and the original cannot be restored exactly.
Lossless compression records the data more efficiently, so the original can be restored exactly. The saving is smaller.
Huffman coding gives the most frequent symbols the shortest binary codes and the rarest the longest, so common text takes fewer bits overall.
The codes are read from a tree, following a branch for each bit until a symbol is reached.
Run length encoding replaces a run of identical values with the value and a count. It saves most on data with long runs, such as a plain background in an image, and can make varied data larger.
Back to Data Representation practice · View all Data Representation questions