3
Decimal to hexadecimal by dividing by 16
ICT Secondary 3 Term 1, Unit 1, Topic 1: pp. 18–21
GoalTurn a decimal number into hexadecimal by repeated division by 16.
New words
remainder 0 to 15 · when dividing by 16 the remainder can be any value from 0 to 15letter digit · a remainder from 10 to 15, written as A to Flower-case hexadecimal · hexadecimal printed with the letters a to f; same value as with capitals
Explanation
The method is the same as for binary, with 16 instead of 2. Divide the number by 16, write the quotient and the remainder, divide the quotient by 16 again, and stop when the quotient is 0. A remainder can be anything from 0 to 15, and the remainders 10 to 15 are written as the letters A to F. Read the remainders from the last to the first. In the table, 677 ÷ 16 = 42 remainder 5; 42 ÷ 16 = 2 remainder 10, written A; 2 ÷ 16 = 0 remainder 2. Reading upwards gives (2A5)₁₆, the number from the last lesson, so the check works. Three hexadecimal symbols are enough for every number up to 4095, because FFF is 4095.
| Division | Quotient | Remainder |
|---|---|---|
| 677 ÷ 16 | 42 | 5 |
| 42 ÷ 16 | 2 | 10 = A |
| 2 ÷ 16 | 0 | 2 |
Worked examples
| Division | Quotient | Remainder |
|---|---|---|
| 1000 ÷ 16 | 62 | 8 |
| 62 ÷ 16 | 3 | 14 = E |
| 3 ÷ 16 | 0 | 3 |
Php
1<?php 2echo dechex(1000), "\n"; 3echo strtoupper(dechex(1000)), "\n"; 4echo hexdec("3E8");
Output
3e8 3E8 1000
Class activity
Convert 150 and 600 to hexadecimal by repeated division by 16, and check each answer by converting it back with place values.
Practice
1
Convert 200 to hexadecimal.
200 ÷ 16 = 12 remainder 8; 12 ÷ 16 = 0 remainder 12 (C). Read upwards: C8.
2
Convert 255 to hexadecimal.
255 ÷ 16 = 15 remainder 15 (F); 15 ÷ 16 = 0 remainder 15 (F). The answer is FF.
3
Convert 100 to hexadecimal.
100 ÷ 16 = 6 remainder 4; 6 ÷ 16 = 0 remainder 6. The answer is 64.
4
Convert 300 to hexadecimal.
300 ÷ 16 = 18 remainder 12 (C); 18 ÷ 16 = 1 remainder 2; 1 ÷ 16 = 0 remainder 1. The answer is 12C.