Number systems and conversions
| English | Chinese | Pinyin |
|---|---|---|
| byte | 字节 | zì jié |
| denary | 十进制 | shí jìn zhì |
| binary | 二进制 | èr jìn zhì |
| bit | 位 | wèi |
| nibble | 半字节 | bàn zì jié |
| hexadecimal | 十六进制 | shí liù jìn zhì |
| register width | 寄存器宽度 | jì cún qì kuān dù |
| kibi | 二进制千 | èr jìn zhì qiān |
The terabyte that was not a terabyte
- In 2005 a Californian bought a hard drive labelled 80 GB. His computer reported 74.5 GB. He sued, and the manufacturers eventually paid out: they had counted a gigabyte as a thousand million bytes, and the operating system had counted it as $2^{30}$.
- Neither was lying. There are two families of prefix, one built on powers of ten and one on powers of two, and they drift further apart the bigger the number gets.
- The whole of data representation rests on that idea: a computer stores nothing but 0s and 1s, and everything else is an agreement about how to read them.
- This lesson is the three number systems, the conversions between them, and the two prefix families.
The three number systems
- Denary 十进制 (base 10) uses digits 0 to 9, with place values that are powers of ten. It is the everyday system.
- Binary 二进制 (base 2) uses 0 and 1, with place values that are powers of two. One digit is a bit 位; 4 bits are a nibble 半字节; 8 bits are a byte 字节.
- Hexadecimal 十六进制 (base 16) uses 0 to 9 then A to F for 10 to 15. One hex digit stands for exactly 4 bits, which is why it is the shorthand programmers use for binary.
| Denary | Binary | Hex |
|---|---|---|
| 10 | 1010 |
A |
| 15 | 1111 |
F |
| 16 | 0001 0000 |
10 |
| 255 | 1111 1111 |
FF |

Every system is place value; only the base changes
Number systems
byte = Σ place values
Each bit is worth a power of two — flip the bits and watch the decimal and hex update.
How many bits does one hexadecimal digit represent?
One hex digit (0–F) covers 16 values = $2^4$, so it maps to exactly 4 bits (a nibble).
How many bits are in one byte?
A byte is 8 bits (and a nibble is 4 bits).
Denary to binary
- Method 1, place values: write the powers of two, $128, 64, 32, 16, 8, 4, 2, 1$, and subtract the largest that fits, repeating with what is left. Put a 1 under each one you used.
- Method 2, repeated division: divide by 2 over and over, writing down each remainder, then read the remainders bottom-up.
- $42 = 32 + 8 + 2$, so the bits under 32, 8 and 2 are 1 and the rest are 0:
0010 1010.

Subtract the biggest power of two that fits, and repeat
Convert denary $13$ to binary (8-bit not required — just the significant bits).
$13 = 8 + 4 + 1$, so the columns 8, 4, 1 are set: 1101.
Convert binary 00101010 to denary.
$32 + 8 + 2 = 42$ (the 32, 8 and 2 columns are set).
Worked example: denary 200 to binary and hex
- $200 = 128 + 64 + 8$, so the 8-bit binary is
1100 1000. - Split into nibbles from the right:
1100is 12, which is C;1000is 8. So the hexadecimal isC8. - Check by place value the other way:
C8$= 12 \times 16 + 8 = 200$. ✓ Always show the working; the conversion itself carries the marks.
Binary and hex, both directions
- Binary to hex: group the bits into nibbles from the right, padding the leftmost group with zeros, and convert each nibble.
0010 0010 1110becomes2 2 E, so22E. - Hex to binary: replace each hex digit with its own 4-bit pattern. No arithmetic needed.
- Hex to denary: multiply each digit by its place value, $16^2 = 256$, $16^1 = 16$, $16^0 = 1$.
22E$= 2 \times 256 + 2 \times 16 + 14 = 558$.
Convert hexadecimal 2E to denary.
$2 \times 16 + 14 = 32 + 14 = 46$ (E is 14).
Convert the binary number 0010 0010 1110 to hexadecimal.
Each nibble converts on its own, from the right: 0010 = 2, 0010 = 2, 1110 = 14 = E.
How many bits does a value need?
- Exam questions fix the register width 寄存器宽度 (8, 12 or 16 bits), and you must pad with leading zeros to that width. $558$ in 12 bits is
0010 0010 1110, never10 0010 1110. - An unsigned integer from 0 to $2^n - 1$ needs $n$ bits: 200 needs 8 bits (8 bits reach 255), 1000 needs 10 bits (10 bits reach 1023), 16 needs 5 bits (4 bits stop at 15).
- One hexadecimal digit needs 4 bits, one BCD digit needs 4 bits, and one ASCII character needs 7 bits, or 8 for extended ASCII.
Write denary 558 as a 12-bit binary number (four bits per group, spaces allowed).
558 = 512 + 32 + 8 + 4 + 2. Pad with leading zeros to the 12 bits the question asks for; an unpadded answer loses the mark.
Worked example: the minimum number of bits
- A system must store values from 0 to 1000. What is the smallest number of bits?
- Ask which power of two first exceeds 1000. $2^9 = 512$, too small; $2^{10} = 1024$, so ten bits hold 0 to 1023 and 1000 fits.
- The answer is 10 bits, and the reason is the range, not the digit count. A common trap: 16 needs five bits, because four bits stop at 15.
What is the smallest number of bits that can store any unsigned value from 0 to 1000?
Nine bits reach 511, ten bits reach 1023. The question is about the range the bits cover, not the number of digits.
Binary prefixes and decimal prefixes
- Decimal prefixes are powers of ten and are used for drive capacities and network speeds: kilo $= 10^3$, mega $= 10^6$, giga $= 10^9$, tera $= 10^{12}$.
- Binary prefixes are powers of two and are used for memory sizes: kibi 二进制千 (Ki) $= 2^{10} = 1024$, mebi (Mi) $= 2^{20}$, gibi (Gi) $= 2^{30}$, tebi (Ti) $= 2^{40}$.
- So a "1 TB" drive holds $10^{12}$ bytes, but an operating system reporting in TiB divides by $2^{40}$ and shows about 0.91. Nothing has been lost; two different units were used.
How many bytes are in 1 kibibyte (KiB)?
A kibibyte is $2^{10} = 1024$ bytes (a binary prefix, used for memory).
A drive sold as 1 TB holds fewer bytes than 1 TiB of memory.
1 TB is 10^12 bytes; 1 TiB is 2^40, about 1.1 x 10^12. Decimal prefixes for drives, binary prefixes for memory.
Where hexadecimal is actually used
- Memory addresses and machine code, because one hex digit is exactly one nibble and a byte is exactly two hex digits, so a dump is readable at a glance.
- Colour codes in web pages:
#FF8800is one byte each of red, green and blue. MAC addresses and error codes likewise. - The reason is always the same: hex is a shorthand for binary that a person can read and write without mistakes, not a system the computer itself uses.
Where is hexadecimal used in practice? Select all that apply.
Hex is a human-readable shorthand for binary: one digit per nibble, two per byte. The processor itself works in binary.
Marks that slip away
- Pad to the width the question gives. An unpadded answer loses the mark even when the bits are right.
- Group nibbles from the right, not the left, or every hex digit shifts.
- 4 bits reach 15, 8 bits reach 255, 10 bits reach 1023. "How many bits" is a question about the range.
- A kibibyte is 1024 bytes and a kilobyte is 1000. Say which you used in any size calculation.
You've got it
- denary base 10, binary base 2 (bit, nibble = 4 bits, byte = 8 bits), hexadecimal base 16 where one digit is exactly one nibble
- denary to binary by subtracting powers of two or by repeated division reading remainders bottom-up; binary to hex by grouping nibbles from the right; hex to denary by place value
- pad to the register width; an unsigned value needs $n$ bits where $2^n$ first exceeds it
- decimal prefixes are powers of ten (drives, networks), binary prefixes powers of two (memory): kibi $= 1024$