Computer Science · Ch 2 — Encoding Schemes and Number System
Conversion from Decimal to other Number Systems
Conversion from Decimal to other Number Systems
One single procedure converts a decimal number into any other number system — binary, octal or hexadecimal. Only the divisor changes: it is always the base value (b) of the target system.
The repeated-division method
- Step 1: Divide the given number by the base value b of the target number system.
- Step 2: Note the remainder.
- Step 3: Keep dividing the quotient by the base value, noting the remainder each time, until the quotient becomes zero.
- Step 4: Write the noted remainders in reverse order (from bottom to top). That string is the converted number.
(A) Decimal to binary conversion
The base of binary is 2, so divide repeatedly by 2. Recall from Figure 2.1 that the binary equivalent of 65 (the ASCII code of 'A') is (1000001)2 — let us verify that by converting (65)10 ourselves:
2 | 65 Remainders
2 | 32 → 1
2 | 16 → 0
2 | 8 → 0
2 | 4 → 0
2 | 2 → 0
2 | 1 → 0
| 0 → 1
Read remainders bottom to top: (65)10 = (1000001)2 ✓
Example 2.3 — Convert (122)10 to binary.
2 | 122 Remainders
2 | 61 → 0
2 | 30 → 1
2 | 15 → 0
2 | 7 → 1
2 | 3 → 1
2 | 1 → 1
| 0 → 1
Bottom to top: (122)10 = (1111010)2
Activity 2.2: convert these decimal numbers to the form understood by a computer (binary): (i) (593)10 (ii) (326)10 (iii) (79)10.
(B) Decimal to octal conversion
The base of octal is 8, so divide repeatedly by 8. The octal equivalent of the letter 'A' using its ASCII code (65)10:
8 | 65 Remainders
8 | 8 → 1
8 | 1 → 0
| 0 → 1
Bottom to top: (65)10 = (101)8
Example 2.4 — Convert (122)10 to octal.
8 | 122 Remainders
8 | 15 → 2
8 | 1 → 7
| 0 → 1
Bottom to top: (122)10 = (172)8
Activity 2.3: express these decimal numbers as octal numbers: (i) (913)10 (ii) (845)10 (iii) (66)10.
(C) Decimal to hexadecimal conversion
The base of hexadecimal is 16, so divide repeatedly by 16. The hexadecimal equivalent of the letter 'A' using its ASCII code (65)10:
16 | 65 Remainders
16 | 4 → 1
| 0 → 4
Bottom to top: (65)10 = (41)16
(Check: 4 × 16 + 1 = 65. This is why the ASCII code of 'A' appears as 41 in hexadecimal listings.)
Example 2.5 — Convert (122)10 to hexadecimal.
16 | 122 Remainders
16 | 7 → 10 → written as the hexadecimal symbol A
| 0 → 7 …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
This figure walks through the repeated-division (division-remainder) method for converting a decimal number to binary, using the ASCII code of the letter 'A' — the decimal number 65 — as the running example.
The heart of the figure is a boxed division ladder. Down the left runs a column of the divisor 2, repeated eight times, and beside it the successive quotients in ruled cells: 65, 32, 16, 8, 4, 2, 1, 0. Each row is one division by 2: 65 ÷ 2 gives quotient 32, 32 ÷ 2 gives 16, and so on until the quotient reaches 0. A "Remainders" column at the right records what each division leaves over, top to bottom: 1, 0, 0, 0, 0, 0, 1. A thick green arrow runs upward alongside the remainders column — the visual cue for the direction in which the answer must be read.
Four green callout banners, connected by arrows to the relevant parts of the ladder, spell out the algorithm:
- Step 1: Divide the decimal number by 2 (at the top, pointing at the first division).
- Step 2: Write its remainder (beside the Remainders column).
- Step 3: Keep dividing each quotient by the base value 2 and note the remainder, until the quotient is zero.
- Step 4: Collect the remainders from bottom to top to get the binary equivalent (at the bottom left).
The result is printed at the bottom right:
(65)10 = (1000001)2
``` …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
This figure applies the repeated-division method to a decimal-to-octal conversion — the same algorithm as Figure 2.5, but with the base value 8 as the divisor. The example is again the ASCII code of the letter 'A', decimal 65.
The boxed division ladder shows a left column of the divisor 8 beside the successive quotients 65, 8, 1, 0: dividing 65 by 8 gives quotient 8, dividing that by 8 gives 1, and one more division reaches 0. The "Remainders" column at the right lists, top to bottom, 1, 0, 1 — the leftovers of the three divisions (65 = 8×8 + 1, 8 = 8×1 + 0, 1 = 8×0 + 1). A thick green upward arrow beside the remainders signals the reading direction for the answer.
Four green callout banners with connector arrows narrate the steps:
- Step 1: Divide the decimal number by 8.
- Step 2: Write its remainder.
- Step 3: Keep dividing the quotient by the base value 8 and note the remainder, until the quotient is zero.
- Step 4: Collect the remainders from bottom to top to get the octal equivalent.
The result appears near the bottom centre:
(65)10 = (101)8
``` …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
This figure completes the trio of repeated-division ladders (Figures 2.5–2.7) by converting the decimal number 65 — the ASCII code of the letter 'A' — into hexadecimal, using the base value 16 as the divisor.
The boxed ladder is the shortest of the three. The left column shows the divisor 16 beside the successive quotients 65, 4, 0: dividing 65 by 16 gives quotient 4 (since 4 × 16 = 64), and dividing 4 by 16 gives quotient 0. The "Remainders" column lists, top to bottom, 1, 4 — the first division leaves remainder 1, the second leaves remainder 4. A green upward arrow beside the remainders marks the reading direction.
Four green callout banners with connector arrows spell out the algorithm:
- Step 1: Divide the decimal number by 16.
- Step 2: Write its remainder.
- Step 3: Keep dividing the quotient by the base value 16 and note the remainder, until the quotient is zero.
- Step 4: Collect the remainders from bottom to top to get the hexadecimal equivalent.
Collecting the remainders bottom-to-top (last remainder first) reads 4 then 1, giving the hexadecimal value 41:
(65)10 = (41)16
Cross-check with positional values: (41)16 = 4×16^1 + 1×16^0 = 64 + 1 = 65. This is why the ASCII code of 'A' is written as 41 in hexadecimal listings. …