Denary to Hexadecimal Conversion
Going through binary is a reliable way to turn a denary number into hexadecimal, because a byte splits neatly into two halves and each half is exactly one hex digit. It also gives you a way to check an answer you found by dividing by 16.
First convert the denary number into 8-bit binary using the place values 128, 64, 32, 16, 8, 4, 2 and 1. Take each place value that fits into what is left over, then pad with leading zeros until there are exactly eight bits.
For 197: 128 fits, leaving 69. The 64 fits too, leaving 5. The 32, 16 and 8 do not fit, but the 4 does, leaving 1, and then the 1 fits. The unused places hold 0, giving 11000101.
Break the eight bits into two nibbles of four bits: 1100 and 0101. Each hex digit represents exactly one nibble, so the left nibble becomes the first hex digit and the right nibble becomes the second. Convert a nibble using its own place values of 8, 4, 2 and 1, and write any total from 10 to 15 as its letter.
| Nibble | Place values used | Denary total | Hex digit |
|---|---|---|---|
| 1100 | 8 + 4 | 12 | C |
| 0101 | 4 + 1 | 5 | 5 |
Reading the two digits in order gives C5, so 197 is C5 in hexadecimal. You can check it: C is 12, and 12 × 16 + 5 = 197.
A nibble can only ever total 0 to 15, which is why this method can never produce a digit beyond F.
A denary number under 16 fits inside four bits, so its left nibble is 0000 and the answer begins with 0. The number 9 is 00001001, which splits into 0000 and 1001: 0 and 9, giving 09 rather than 9. Keeping the zero means the answer is always two hex digits long, matching one byte.
OCR GCSE Computer Science · Denary to Hexadecimal Conversion