Denary to Hexadecimal Conversion
To turn a denary whole number from 0 to 255 into hexadecimal, divide it by 16. The whole-number part of the answer and the remainder give you the two hex digits, one each.
The whole-number part of the division is called the quotient. It counts how many whole 16s fit into the number, so it becomes the left hex digit. The remainder is what is left over; it counts the 1s, so it becomes the right digit.
For example, 150 ÷ 16 = 9 remainder 6. The quotient 9 is the left digit and the remainder 6 is the right digit, so 150 is 96 in hexadecimal. The place values confirm it: 9 × 16 = 144, and 144 + 6 = 150.
Dividing by 16 always leaves a remainder from 0 to 15, so the remainder fits in one hex digit. For a number up to 255, the quotient is at most 15, so it fits in one digit as well. Any quotient or remainder from 10 to 15 must be written as its letter (10 = A up to 15 = F). For example, 43 ÷ 16 = 2 remainder 11, so 43 is 2B. Writing it as 211 would be wrong, because each character must be a single hex digit from 0 to F and the answer must be exactly two characters long.
If the denary number is smaller than 16, no whole 16 fits into it, so the quotient is 0. The answer still needs two digits, so write the 0 first. For example, 5 ÷ 16 = 0 remainder 5, giving 05, not 5. The left digit is worth 0 × 16 = 0 and the right digit is worth 5, which together make 5.
Always put the quotient before the remainder. Swapping them changes the value completely: 96 means 9 × 16 + 6 = 150, while 69 means 6 × 16 + 9 = 105.
OCR GCSE Computer Science · Denary to Hexadecimal Conversion