What you'll learn
Everything a computer stores is binary. A photograph, a song, a letter and the program displaying them are all the same kind of thing underneath — patterns of bits — and this topic is about how each is encoded and how much space it takes. By the end of this guide you should be able to convert between binary, denary and hexadecimal, add binary numbers and recognise overflow, perform binary shifts and say what they do to the value, explain how text, images and sound are represented, and calculate the size of an image file and a sound file from their properties.
Key terms and definitions
Bit — A single binary digit, either 0 or 1; the smallest unit of data.
Nibble — Four bits, exactly half a byte, which maps onto one hexadecimal digit.
Byte — Eight bits.
Denary — The ordinary base-10 number system using digits 0 to 9.
Binary — The base-2 system using only 0 and 1.
Hexadecimal — The base-16 system using digits 0 to 9 and letters A to F.
Overflow — What occurs when a result needs more bits than are available to store it.
Character set — A table matching each character to a unique binary code, such as ASCII or Unicode.
Resolution — The number of pixels in an image, usually given as width × height.
Colour depth — The number of bits used to store the colour of each pixel.
Sample rate — The number of audio samples taken per second, measured in hertz.
Sample resolution — The number of bits used to store each individual audio sample.
Metadata — Data about the data, such as an image's dimensions and the date it was taken.
Core concepts
Why binary
A circuit can reliably distinguish two states — on and off, high and low — far more dependably than it could distinguish ten. Everything else follows from that engineering fact: all representation has to be built out of two symbols.
Binary to denary
Write the place values above the digits, doubling from right to left: 128, 64, 32, 16, 8, 4, 2, 1. Add the place values wherever there is a 1. So 11010 is 16 + 8 + 2 = 26.
Denary to binary
Work down from the largest place value that fits. For 25: 16 fits, leaving 9; 8 fits, leaving 1; 1 fits, leaving 0. The 16, 8 and 1 columns hold a 1, giving 00011001 as eight bits. Always check by adding the place values back up.
Hexadecimal
One hex digit stands for exactly four bits, which is the entire reason hex exists: a byte becomes two characters instead of eight, and errors are far easier to spot. The digits run 0–9 then A–F, where A is 10 and F is 15.
- Hex to denary: the left digit is worth 16 each. So 2F is (2 × 16) + 15 = 47.
- Denary to hex: divide by 16; the quotient is the left digit and the remainder the right. So 200 ÷ 16 = 12 remainder 8, and 12 is C, giving C8.
- Binary to hex: split into nibbles and convert each. 10110110 becomes 1011 and 0110, which are 11 and 6, giving B6.
The computer gains nothing from hex — it still works in binary. Hex is purely a convenience for the people reading it.
Units of information
Each unit is 1 000 times the one before: bit, byte, kilobyte (kB), megabyte (MB), gigabyte (GB), terabyte (TB), petabyte (PB). Four bits is a nibble and eight is a byte.
Binary addition
Add column by column from the right, carrying 1 into the next column whenever a column totals 2 (which is 10 in binary). Where three 1s meet, the result is 1 with a carry of 1.
Overflow
With a fixed number of bits there is a largest representable value, and a result beyond it cannot be stored. Overflow is dangerous because the program usually continues running with a silently wrong value rather than stopping. Using more bits raises the limit but never removes it.
Binary shifts
Shifting left moves every bit into a column worth twice as much, so one place multiplies by 2 and n places multiply by 2ⁿ. Shifting right divides instead, and any bits falling off the end are lost — which is why a right shift can lose precision.
Representing text
A character set maps each character to a binary code. Basic ASCII uses 7 bits and so covers only 128 characters — enough for English and little else. Unicode uses more bits per character and covers many world alphabets and symbols, at the cost of larger files. The codes are arranged so that the letters run in sequence, which is what lets a program sort alphabetically by comparing numbers.
Representing images
A bitmap image is a grid of pixels, each storing a colour.
- Resolution is the number of pixels (width × height).
- Colour depth is the bits per pixel. More bits allow more distinct colours: n bits give 2ⁿ colours.
Image data size (bits) = width × height × colour depth. Divide by 8 for bytes.
Real files are slightly larger than this calculation because of metadata — the dimensions, colour depth and date have to be stored too, and without them the pixel values could not be displayed at all.
Representing sound
Sound is a continuous wave, and a computer stores it by sampling: measuring the wave's height at regular intervals.
- Sample rate is measurements per second. A higher rate follows the wave more closely.
- Sample resolution is bits per sample. More bits allow a finer distinction between loudness levels.
Sound data size (bits) = sample rate × sample resolution × duration in seconds. Divide by 8 for bytes. Raising any one of the three factors raises the file size in direct proportion.
Compression
Lossless compression stores the same information more economically, so decompression rebuilds the file bit for bit. It is essential for text, spreadsheets and program code, where one altered character could change the meaning.
- Run-length encoding (RLE) records a run of identical values once with a count. It works brilliantly on large flat areas of one colour and can make a detailed photograph larger than the original, because adjacent pixels rarely match.
- Huffman coding gives the most frequent characters the shortest binary codes. Fixed-length encoding spends the same 8 bits on a rare letter as on a common one, and Huffman removes that waste.
Lossy compression permanently discards data judged least noticeable. It achieves much smaller files and cannot be reversed to the exact original — which is precisely what the word lossy records.
Worked examples
Example 1: Image file size
A bitmap is 100 pixels wide, 50 pixels high, with a colour depth of 8 bits.
Size in bits = 100 × 50 × 8 = 40 000 bits. In bytes: 40 000 ÷ 8 = 5 000 bytes.
The standard error is to report 40 000 bytes. That figure is in bits — the division by 8 has been forgotten.
Example 2: Sound file size
A mono recording is made at 8 000 samples per second with 8-bit samples, for 10 seconds.
Size in bits = 8 000 × 8 × 10 = 640 000 bits. In bytes: 640 000 ÷ 8 = 80 000 bytes.
Now halve the sample rate to 4 000 Hz. Size becomes 4 000 × 8 × 10 = 320 000 bits = 40 000 bytes — exactly half, because size is directly proportional to the rate. Quality drops along with the size.
Example 3: Binary addition and overflow
Add 00101101 and 00010011.
These are 45 and 19, so the answer should be 64. Working right to left, the first six columns each produce a 0 with a carry, giving 01000000 — which is 64. Correct.
Now add 10100000 and 01100000 using only 8 bits. These are 160 and 96, totalling 256, which in binary is 100000000 — nine digits. Only the lower eight can be kept, so the stored result is 00000000 and the carry is lost. The answer is not merely imprecise, it is completely wrong: this is overflow.
Example 4: A binary shift
Shift 11010000 two places right.
The result is 00110100. Checking the values: 11010000 is 208 and 00110100 is 52, which is exactly a quarter. Each place shifted right halves the value, so two places divide by 2² = 4.
Common mistakes and how to avoid them
The single most frequent error in file-size questions is forgetting to divide by 8. The formula gives bits; the question usually wants bytes. Write "bits" beside your first figure so you remember it is not the answer yet.
In hexadecimal, F is 15, not 14 — the digits start at zero, so A is 10 and F is 15.
When converting denary to hex, the quotient goes on the left and the remainder on the right. Writing C8 as 8C is the usual slip.
When converting binary to hex, keep the left nibble on the left. Reversing 10110110 gives 6B instead of B6.
Do not confuse sample rate with sample resolution. The rate is how often the wave is measured; the resolution is how many bits each measurement uses. Both affect quality and size, and they are separate settings.
Remember that lossy compression cannot be reversed, and that run-length encoding can increase the size of a detailed image.
Finally, do not claim hexadecimal saves the computer memory. Hex is a notation for humans; the stored data is binary either way, and the choice of notation uses no memory at all.
Exam technique for "Fundamentals of Data Representation"
Show every step of a conversion. Write the place-value row above a binary number before you start, and for hex write the nibbles out separately — method marks are available even when the arithmetic slips.
For file-size calculations, state the formula first, substitute the numbers, give the answer in bits, then convert. Always include the unit, and say explicitly whether the figure is bits or bytes.
When a question asks for the effect of changing a setting, give the direction and the reason: "doubling the sample rate doubles the file size, because size is directly proportional to the rate." A bare "it gets bigger" earns little.
For compression questions, name the type, say whether data is lost, and give a use case that fits. Where the question offers a scenario, let the scenario decide: text and code need lossless, a streamed photograph can take lossy.
Quick revision summary
- Place values double right to left: 128, 64, 32, 16, 8, 4, 2, 1.
- One hex digit = four bits; A = 10 and F = 15. 2F = 47; 200 = C8; 10110110 = B6.
- 4 bits = a nibble, 8 bits = a byte; n bits give 2ⁿ different values.
- Overflow occurs when a result needs more bits than are available, and the stored value is silently wrong.
- Shift left to multiply, right to divide, by 2ⁿ for n places.
- ASCII is 7 bits and 128 characters; Unicode covers world alphabets using more bits.
- Image size (bits) = width × height × colour depth. Example: 100 × 50 × 8 = 40 000 bits = 5 000 bytes.
- Sound size (bits) = sample rate × sample resolution × duration. Example: 8 000 × 8 × 10 = 640 000 bits = 80 000 bytes.
- Lossless (RLE, Huffman) restores the original exactly; lossy discards data permanently for a smaller file.
- Always divide by 8 to turn bits into bytes.