Learn
1.1.2 | BINARY, HEX AND CONVERSIONS
HEX IN EVERYDAY COMPUTING
Hexadecimal appears wherever people need to read or write binary values compactly. One hex digit stands for four bits, so a long binary pattern becomes shorter without changing its value.
| Use | Example | Why hex helps |
|---|---|---|
| Web colour codes | #24988F | Six hex digits represent three colour channels compactly. |
| Memory addresses | 0x1A2F | Programmers can inspect locations without reading a long binary pattern. |
| MAC addresses | 02:1A:2B:3C:4D:5E | A typical 48-bit MAC address can be written as six two-digit hex groups. |
| Diagnostic and error codes | 0x2F | A compact code is easier to display, copy and look up, including on a small device screen. |
| Debugging raw data | AF 3C 12 | Each pair represents a byte, making stored data easier to inspect. |
These address and diagnostic examples illustrate notation, not a particular real device or error. A code’s meaning depends on the system’s documentation. The prefix 0x commonly identifies a hex number in programming; it is not part of the digits used in your conversion answers.
Hex is easier for humans to handle, but the computer still represents and processes the underlying data in binary. Further benefits are explored in 1.1.3.
COLOUR CODES | THREE PAIRS, THREE CHANNELS
A six-digit web colour code follows #RRGGBB: two hex digits each for red, green and blue. Each pair ranges from 00 to FF, representing a channel value from 0 to 255.
Red: 24₁₆ = 36₁₀
Green: 98₁₆ = 152₁₀
Blue: 8F₁₆ = 143₁₀
This is the green accent used on this website. In RGB notation it is rgb(36, 152, 143). The six hex digits describe 24 bits of colour-channel data: three channels of eight bits each.
| Colour | Hex code | Red, green, blue | Sample |
|---|---|---|---|
| Red | #FF0000 | 255, 0, 0 | |
| Blue | #0000FF | 0, 0, 255 | |
| White | #FFFFFF | 255, 255, 255 | |
| Black | #000000 | 0, 0, 0 |
The colour-code example uses more than 16 bits overall to show a real application. The syllabus conversion exercises on this page stay within 16 bits.
01 | SAME VALUE, DIFFERENT NOTATION
A computer stores a value as bits. A programmer may write that same value in denary or hexadecimal to make it easier to read. Changing the number system changes the notation, not the underlying quantity.
Denary is base 10, using 0 to 9. Binary is base 2, using 0 and 1. Hexadecimal is base 16, using 0 to 9 and A to F.
| System | Base | Example representing forty-five |
|---|---|---|
| Denary | 10 | 45 |
| Binary | 2 | 00101101 |
| Hexadecimal | 16 | 2D |
Subscripts identify a base when necessary: 45₁₀, 00101101₂ and 2D₁₆. Without a base label, “10” is ambiguous: it can mean ten, two or sixteen.
This lesson uses unsigned whole-number values up to 16 bits. Negative-number representation is covered in 1.1.6.
02 | PLACE VALUE IS THE KEY
In denary, moving one position left multiplies the place value by 10: 1, 10, 100. Binary uses powers of 2, so its place values double. Hexadecimal uses powers of 16.
| System | Four place values, left to right |
|---|---|
| Denary | 1000, 100, 10, 1 |
| Binary | 8, 4, 2, 1 |
| Hexadecimal | 4096, 256, 16, 1 |
| 16³ | 16² | 16¹ | 16⁰ |
|---|---|---|---|
| 4096 | 256 | 16 | 1 |
| 1 | 2 | 3 | 4 |
| 1 × 4096 = 4096 | 2 × 256 = 512 | 3 × 16 = 48 | 4 × 1 = 4 |
1234₁₆ = 4096 + 512 + 48 + 4 = 4660₁₀. Start at the right with 1, then move left through 16, 256 and 4096. The place values are denary values, even though the digits placed in those columns are hexadecimal digits.
The specification allows binary lengths up to 16 bits, equivalent to four hex digits. That is why all four columns are included.
Each digit contributes digit × place value. Add those contributions to find the denary value. In binary, a 1 includes that place value and a 0 contributes nothing.
03 | BINARY TO DENARY: ADD THE ONES
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 |
00101101₂ = 32 + 8 + 4 + 1 = 45₁₀
Start at the right with 1 and double as you move left. Include only the columns with a 1. Leading zeros do not add anything.
Quick check: the leftmost 1 is in the 32 column, so the answer must be at least 32 and less than 64.
04 | DENARY TO BINARY: CHOOSE PLACE VALUES
To convert 156 to an 8-bit pattern, start with 128. Put 1 in a column if its value fits into the amount remaining; otherwise put 0.
| Place value | Decision | Remaining |
|---|---|---|
| 128 | Use it: write 1 | 28 |
| 64 | Too large: write 0 | 28 |
| 32 | Too large: write 0 | 28 |
| 16 | Use it: write 1 | 12 |
| 8 | Use it: write 1 | 4 |
| 4 | Use it: write 1 | 0 |
| 2 | Write 0 | 0 |
| 1 | Write 0 | 0 |
156 = 128 + 16 + 8 + 4 156₁₀ = 10011100₂
Finish all the columns required by the question. If it asks for 8 bits, write exactly eight bits, including leading zeros where needed.
05 | ANOTHER METHOD: DIVIDE BY TWO
Repeated division is an alternative to choosing place values. Divide by 2, record the remainder and continue with the whole-number quotient until it reaches zero.
| Division | Quotient | Remainder |
|---|---|---|
| 45 ÷ 2 | 22 | 1 |
| 22 ÷ 2 | 11 | 0 |
| 11 ÷ 2 | 5 | 1 |
| 5 ÷ 2 | 2 | 1 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Read the remainders from bottom to top: 101101. Pad on the left for an 8-bit answer: 00101101.
Reading the remainders downwards is a common mistake. Check by converting your final binary pattern back to denary.
06 | HEX DIGITS AND FOUR-BIT GROUPS
Hex needs six symbols beyond 9: A=10, B=11, C=12, D=13, E=14 and F=15. The next value after F is 10₁₆, which means sixteen in denary.
| Denary | Hex | Four-bit binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
One hex digit corresponds to four bits, because four bits have 2⁴ = 16 patterns. A group of four bits is called a nibble.
Hex is a compact way to write the bits. It does not mean that the computer stores a letter A instead of its binary pattern.
07 | CONVERT DIRECTLY BETWEEN BINARY AND HEX
Binary to hex: group bits in fours from the right. Pad the leftmost group with zeros if needed, then convert each group separately.
10101111₂ → 1010 1111 → A F → AF₁₆ 10010₂ → 0001 0010 → 1 2 → 12₁₆
8 + 2 = 10
A8 + 4 + 2 + 1 = 15
FKeep the groups in the same left-to-right order: A then F.
Hex to binary: replace each hex digit with its four-bit pattern, preserving the zeros within each group.
3C₁₆ → 3 = 0011, C = 1100 3C₁₆ = 00111100₂
Writing 3 as 11 and simply joining it to 1100 loses the four-bit grouping. Write each nibble in full first, then adjust the overall width only if the question allows it.
08 | HEX TO DENARY: MULTIPLY AND ADD
2A₁₆ = (2 × 16) + (10 × 1) = 42₁₀
12C₁₆ = (1 × 256) + (2 × 16) + (12 × 1)
= 256 + 32 + 12 = 300₁₀Convert letter digits to their denary values before multiplying. The rightmost place is 1, then 16, then 256, then 4096.
Common mistake: treating 12₁₆ as twelve in denary. It is (1 × 16) + 2 = 18₁₀.
09 | DENARY TO HEX: DIVIDE BY SIXTEEN
| Division | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 300 ÷ 16 | 18 | 12 | C |
| 18 ÷ 16 | 1 | 2 | 2 |
| 1 ÷ 16 | 0 | 1 | 1 |
Read the remainder digits from bottom to top: 12C₁₆. Check it by multiplying through the hex place values.
You can also convert denary to binary first, then group the bits into nibbles. Use the method you can explain and check reliably.
10 | EXTEND TO SIXTEEN BITS
The method stays the same for longer patterns. Sixteen binary bits correspond to four hex digits. The largest unsigned 16-bit value is 2¹⁶ − 1 = 65535; there are 65536 possible values including zero.
1234₁₆ = 0001 0010 0011 0100₂ = (1 × 4096) + (2 × 256) + (3 × 16) + 4 = 4660₁₀ 511₁₀ = 0000 0001 1111 1111₂ = 01FF₁₆
Leading zeros preserve an unsigned value but show a required width. 1FF and 01FF have the same value; use four digits when the question requests that format.
11 | EXPLORE AND CHECK A VALUE
Enter an unsigned value in one system. The explorer displays the equivalent denary, 16-bit binary and four-digit hex. Try your own conversion first, then use it to check.
12 | PRACTISE WITHOUT THE EXPLORER
Use the methods above and show your working. For longer conversions, keep each four-bit group clearly spaced while calculating.