Binary Numbers, Two's Complement and Hexadecimal
Why Computers Use Binary
Every piece of data inside a computer — text, images, sound, instructions — is stored and processed as a pattern of 1s and 0s. This is the binary (base-2) number system. A transistor in a chip is either conducting electricity or not — that two-state physical reality maps perfectly onto binary’s two digits. A bit is a single binary digit. Eight bits make one byte.
The number of distinct states that can be represented by a binary pattern of a given length is always a power of 2. One bit gives 2 states (0 or 1). Two bits give 4 states (00, 01, 10, 11). Eight bits give \(2^8 = 256\) states. In general, \(n\) bits can represent \(2^n\) different values.
An 8-bit binary number has place values 128 — 64 — 32 — 16 — 8 — 4 — 2 — 1 (left to right). To convert binary to denary, add up the place values where the digit is 1. The maximum unsigned 8-bit value is 11111111 = 255; the minimum is 00000000 = 0.
Converting Between Binary and Denary
Denary (decimal) uses place values that are powers of 10. Binary uses powers of 2. Converting binary to denary means reading off the place values where a 1 appears and adding them together.
Binary → Denary: Convert 10110101
Place values: 128 64 32 16 8 4 2 1
Bits: 1 0 1 1 0 1 0 1
Values that count: 128 + 32 + 16 + 4 + 1 = 181
Denary → Binary: Convert 203
128 fits: 203 − 128 = 75, write 1
64 fits: 75 − 64 = 11, write 1
32 does not fit in 11, write 0
16 does not fit in 11, write 0
8 fits: 11 − 8 = 3, write 1
4 does not fit in 3, write 0
2 fits: 3 − 2 = 1, write 1
1 fits: 1 − 1 = 0, write 1
Result: 11001011
Check: 128 + 64 + 8 + 2 + 1 = 203 ✓
Two’s Complement — Representing Negative Numbers
Unsigned binary can only represent positive integers and zero. To store negative integers, computers use two’s complement. In 8-bit two’s complement, the most significant bit (leftmost bit) has a place value of −128 instead of +128. The remaining seven bits retain their normal positive place values.
This means 8-bit two’s complement can represent integers from −128 to +127. Positive numbers look the same as unsigned binary — the most significant bit is 0. Negative numbers have the most significant bit set to 1.
In 8-bit two’s complement the place values are −128, 64, 32, 16, 8, 4, 2, 1. The range is −128 to +127. To convert a negative pattern to denary, treat the leftmost bit as −128 and add the remaining place values as normal.
How to represent −5 in 8-bit two’s complement:
Step 1 — Write +5 in 8-bit binary: 00000101
Step 2 — Invert all bits (flip every 0 to 1 and every 1 to 0): 11111010
Step 3 — Add 1 to the result: 11111010 + 00000001 = 11111011
Check: Using place value −128 + 64 + 32 + 16 + 8 + 2 + 1 = −128 + 123 = −5 ✓
Converting 10010011 back to denary:
Place value of leftmost bit = −128
Remaining bits 0010011: 16 + 2 + 1 = 19
Total: −128 + 19 = −109
Hexadecimal
Hexadecimal (hex, base-16) uses 16 symbols: digits 0–9 and letters A–F, where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Hex is used because it is a compact shorthand for binary: every four bits (one nibble) maps to exactly one hex digit, making long binary strings much easier for humans to read.
You will see hex everywhere in computing: web colour codes (#FF5500), MAC addresses on network cards, memory dump listings in diagnostic tools. The maximum 8-bit value is FF in hex (255 in denary). Computers do not process hex directly — it is a human convenience for working with binary patterns.
Binary → Hex: Convert 11010110
Split into nibbles: 1101 | 0110
1101 = 13 = D
0110 = 6
Result: D6
Hex → Binary: Convert 3A
3 = 0011
A = 10 = 1010
Result: 00111010
Hex → Denary: Convert 3A
(3 × 16) + 10 = 48 + 10 = 58
To convert binary to hex: split into groups of 4 bits (nibbles) from the right, then convert each nibble to its hex digit. To convert hex to denary: multiply the first digit by 16, add the second digit. Hexadecimal is used in computing because one hex digit represents exactly four binary bits — making large binary numbers compact and readable.