الأسبوع 15 · مراجعة الفصل الدراسي الأول (الوحدتان ١ و٢) ومشروع صغير من تصميمك · 3 دروس
1
Review: number systems and conversions
ICT Secondary 3 Term 1, Review: pp. 5–86
GoalReview digits, place values, binary, hexadecimal and the six conversions with new numbers, and check each answer by going back.
New words
place value · the value of a place in a number: a power of the basebase · the number of symbols of a system: 2, 10 or 16check by going back · convert the answer back; you must reach the starting numberbyte · 8 bits, which is two hexadecimal symbols
Explanation
Here is Unit 1 in one page. A digit is one symbol and a number is made of digits; its value comes from place values, which are powers of the base (Week 1). Computers use only 0 and 1 because circuits have two states. A bit is one binary digit, a byte is 8 bits, n bits make 2ⁿ patterns, and 1 KB is 1,024 bytes (Week 2). In binary the place values are 1, 2, 4, 8, and so on; to go from decimal to binary we divide by 2 and read the remainders from the last to the first (Week 3). Hexadecimal has sixteen symbols, 0 to 9 and A to F, and place values 1, 16, 256; to go from decimal we divide by 16 and write the remainders 10 to 15 as A to F (Week 4). Because 16 = 2⁴, each hexadecimal symbol is four bits, so we convert between hexadecimal and binary in groups of four from the right (Week 5). The converter programs of Weeks 6 and 7 call ready functions that do these conversions, give hexadecimal in lower case, and fail on bad input, so a good program checks the text first. Every answer on this page is checked by going back.
Conversion
Method
binary to decimal
multiply each bit by its place value 1, 2, 4, 8 … and add
decimal to binary
divide by 2 again and again; read the remainders from last to first
hexadecimal to decimal
multiply each symbol by 1, 16, 256 … and add
decimal to hexadecimal
divide by 16; the remainders 10 to 15 are A to F; read last to first
hexadecimal to binary
four bits for each symbol
binary to hexadecimal
groups of four bits from the right, padded on the left
Worked examples
Division
Quotient
Remainder
52 ÷ 2
26
0
26 ÷ 2
13
0
13 ÷ 2
6
1
6 ÷ 2
3
0
3 ÷ 2
1
1
1 ÷ 2
0
1
Decimal 52 to binary, step by step. Read the remainders from the last to the first: 110100.
The same checks in PHP. The ready functions give hexadecimal in lower case, so strtoupper makes capitals, and str_pad restores the leading zeros. The output lines come from running it.
The same checks in VB.NET, inside a small console program. Convert.ToString(1500, 16) gives lower case, so ToUpper makes capitals. Bad input fails: Convert.ToInt32("1021", 2) raises a FormatException because 2 is not a binary symbol, and PHP’s bindec("1021") quietly ignores the 2 (with a notice) and gives 5.
Class activity
Convert on paper: decimal 75 to binary, binary 101101 to decimal, hexadecimal 2F8 to decimal, decimal 900 to hexadecimal, and hexadecimal C5 to binary. Check each answer by going back.
Practice
1
How many patterns can 7 bits make?
128, because 2⁷ = 128.
2
How many bits does a menu of 20 choices need, if every choice gets its own pattern?
5 bits: 2⁴ = 16 is too small and 2⁵ = 32 is enough.
3
How many hexadecimal symbols make one byte?
Two.
4
Why should the converter program check its input?
Letters or empty text make the ready functions fail or give strange results.