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

Binary, hex and characters

الأسبوع 4 · الوحدة ٦ «تصميم المعلومات» (١): التناظري والرقمي، النظام الثنائي وكمية المعلومات، النظام السداسي عشر، تمثيل الحروف رقميًا · 3 دروس
2

Counting in two and in sixteen

ICT Secondary 1 Term 1, Chapter 6, Lessons 6-1 to 6-4: pp. 53–64
GoalConvert between binary, decimal and hexadecimal by place values and by groups of four bits.
New words
binary · the number system with only the digits 0 and 1place value · what a digit is worth because of its positionhexadecimal · the base-16 system with digits 0–9 and A–Fdecimal · the everyday base-10 system
Explanation

In decimal each place is worth ten times the place on its right. In binary each place is worth two times the place on its right, so the places of 8 bits are 128, 64, 32, 16, 8, 4, 2, 1. To read a binary number, add the place values where the digit is 1: 1011 0101 is 128 + 32 + 16 + 4 + 1 = 181. To write a decimal number in binary, divide by 2 again and again and keep the remainders; read them from the last to the first. For 37: 37 ÷ 2 = 18 remainder 1, 18 ÷ 2 = 9 r 0, 9 ÷ 2 = 4 r 1, 4 ÷ 2 = 2 r 0, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1; reading upward gives 100101. Binary numbers get long, so people use hexadecimal, which has 16 digits: 0 to 9 and then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. One hex digit stands for exactly four bits. To convert, cut the bits into groups of four, starting at the right-hand end: 1010 0111 is A and 7, so A7. Check: A7 = 10 × 16 + 7 = 167, and 1010 0111 = 128 + 32 + 4 + 2 + 1 = 167. The biggest byte, 1111 1111, is FF = 255. Colour codes on web pages are written in hex.

Place value1286432168421
1011 010110110101
worth128321641
Worked examples
DivisionQuotientRemainder
37 ÷ 2181
18 ÷ 290
9 ÷ 241
4 ÷ 220
2 ÷ 210
1 ÷ 201
Convert decimal 37 to binary by division by 2. The remainders, read upward, are 1, 0, 0, 1, 0, 1. Check by place values: 32 + 4 + 1 = 37.
HexBitsHexBits
0000081000
1000191001
20010A1010
30011B1011
40100C1100
50101D1101
60110E1110
70111F1111
Hex and binary go together by groups of four. The table lists each hex digit with its four bits. Convert 2F to binary: 2 is 0010 and F is 1111, so 2F is 0010 1111 = 47.
Class activity

Without a device, convert these: decimal 20 to binary; binary 0110 1001 to decimal and to hex; hex 3C to binary. Check each answer by converting it back.

Practice
1
Convert binary 1010 to decimal.
2
Convert decimal 11 to binary.
3
Convert hex 2D to decimal.
4
Why do people use hexadecimal when computers work in binary?