☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

Hexadecimal numbers

الأسبوع 4 · الوحدة ١ «النظم العددية» (٤): النظام السداسي عشر، التحويل من السداسي عشر إلى العشري ومن العشري إلى السداسي عشر · 3 دروس
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.

DivisionQuotientRemainder
677 ÷ 16425
42 ÷ 16210 = A
2 ÷ 1602
Worked examples
DivisionQuotientRemainder
1000 ÷ 16628
62 ÷ 16314 = E
3 ÷ 1603
Convert 1000 to hexadecimal. 1000 ÷ 16 = 62 remainder 8; 62 ÷ 16 = 3 remainder 14, written E; 3 ÷ 16 = 0 remainder 3. Read upwards: (3E8)₁₆. Check: 3×256 + 14×16 + 8 = 768 + 224 + 8 = 1000.
Php
1<?php
2echo dechex(1000), "\n";
3echo strtoupper(dechex(1000)), "\n";
4echo hexdec("3E8");
Output
3e8
3E8
1000
PHP has ready functions for this. dechex writes a number in hexadecimal with lower-case letters, strtoupper turns them into capitals, and hexdec converts back to decimal.
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.
2
Convert 255 to hexadecimal.
3
Convert 100 to hexadecimal.
4
Convert 300 to hexadecimal.