Skip to content

← Grade 9 Computer

Number System

Unit 2 · CDC textbook pages 41–52

Hide the stories, facts, photos, activities and interactives, for revising before an exam
In this unit 4 sections
  1. 2.1 Concept of number system
  2. 2.2 Binary calculation
  3. 2.3 Number conversion
  4. Exercise

Hold up your two hands and count to ten on your fingers. That is where our way of writing numbers comes from: ten fingers, ten digits, 0 to 9. A computer has no fingers. Deep inside, it has billions of tiny switches, and each switch can only be off or on. So a computer counts with just two digits, 0 and 1, and writes everything with them: the year 2082 BS is 100000100010 to a computer, and so is every photo, song and message on your phone.

This unit is about how numbers are written in different number systems: the decimal system you use every day, the binary system computers use, and the octal and hexadecimal systems programmers use as shorthand for binary. You will add and subtract in binary, and change a number from one system to another, by hand, the way the exam asks.

2.1 Concept of number system

Long before anyone wrote numbers down, people counted on their fingers, cut notches in sticks, piled up pebbles, and tied knots in ropes. Shepherds kept one pebble for each sheep; the Inca of South America kept the accounts of a whole empire on bundles of knotted strings called quipus. Over thousands of years people invented ways of writing numbers, and then machines to calculate with them: the abacus, mechanical calculators, and finally electronic computers.

Two quipus on white boards in a museum: many thin cotton strings hanging from a main cord, with small knots tied along them
Figure 2.1 Inca quipus in the Larco Museum, Lima, Peru. Each string holds a number in its knots: the knots farthest from the main cord count the ones, the next group the tens, then the hundreds. It is a decimal place-value system, tied in cotton. Photo: bobistraveling, CC BY 2.0

Today you meet numbers everywhere: a bus fare of Rs. 35, a mobile number, a 2 GB data pack, a mark of 87 out of 100. All of these are written in one number system.

A number system is a way of writing numbers: a set of symbols (digits) and rules for using them to show any number and to calculate with it. When we count things, we use the decimal number system, which has 10 symbols, 0 to 9. With those ten symbols we can write any number at all, however large, because the same digit means more or less depending on where it stands. It is easy to use and understand, so it is the number system of daily life everywhere in the world.

Digits, places and the base

Many number systems are in use, and they differ in their base. The base or radix of a number system is the total number of digits it uses. Decimal uses ten digits, so its base is 10.

In all four number systems of this unit, a digit’s position decides what it is worth (Roman numerals, still seen on clock faces, are not like this: X is ten wherever it stands). Positions are counted from the right, starting at 0. The digit in position 0 is worth itself; each place to the left is worth base times the place before it. So the place value of a position is the base raised to that position: base⁰ = 1, base¹, base², base³ and so on. This is why such a system is called a positional (place-value) number system.

The same digits mean different numbers in different bases, so when bases are mixed we write the base small after the number, in brackets: (1101)₂ is a binary number, (1101)₁₀ a decimal one. Look at both in Figure 2.2.

Decimal, base 10positionpower of baseplace valuedigit310³1,0001210²1001110¹102010⁰1510base1 × 1,000 + 1 × 100 + 2 × 10 + 5 × 1 = 1,125Binary, base 2positionpower of baseplace valuedigit32³8122²4112¹2002⁰112base1 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 13
Figure 2.2 The parts of a number. Each digit has a position, counted from 0 at the right; its place value is the base to the power of its position. The same pattern of digits, 1101, is a different number in base 10 and in base 2, because the places are worth different amounts.

There are four number systems you need to know:

  • the decimal number system (base 10)
  • the binary number system (base 2)
  • the octal number system (base 8)
  • the hexadecimal number system (base 16)

Decimal number system

The decimal number system is the one we use in daily life. It has base 10, because it uses ten digits, 0 to 9. Each position stands for a power of 10: units (ones), tens, hundreds, thousands and so on. In 719, the 9 is in the units place, the 1 in the tens place and the 7 in the hundreds place:

(719)10=(7×100)+(1×10)+(9×1) (719)_{10} = (7 \times 100) + (1 \times 10) + (9 \times 1)
=(7×102)+(1×101)+(9×100) \qquad = (7 \times 10^2) + (1 \times 10^1) + (9 \times 10^0)
=700+10+9=719 \qquad = 700 + 10 + 9 = 719

Remember that any number to the power 0 is 1: 10⁰ = 1, 2⁰ = 1, 16⁰ = 1.

Binary number system

The binary number system uses only two digits, 0 and 1, so it is a base-2 number system. A binary digit is called a bit (short for binary digit), and 8 bits make a byte. For example, (110111)₂ is a binary number of six bits.

Binary is the number system of computers. A computer is built from electronic switches, and a switch has two states: off (0) or on (1). In the same way a magnetic spot on a hard disk points one of two ways, a pit on a CD is there or not, and a wire carries a low or a high voltage. Two states are easy to make and very hard to mix up, so computers store and process everything, numbers, letters, pictures and sound, as patterns of 0s and 1s.

In binary the places are powers of 2: from the right, 1, 2, 4, 8, 16, 32, 64, 128, each double the one before.

Try it

Bits and their place values

Tap a bit to switch it on (1) or off (0), or type a number from 0 to 255. Each bit that is on adds its place value. Try to make 100, then 255, the biggest number a byte can hold.

Binary
00110111
Number
55

55 = 32 + 16 + 4 + 2 + 1

Tap a bulb to switch it on (1) or off (0).

The left bit is off, so the number is 0 or more: the other bits add up as usual.

0 and then all 1s: 255, the biggest number 8 bits can show this way. Add 1 and it becomes 0.

Each bit that is on adds its place value to the number. A bit that is off adds nothing.

Adding 1: the bit worth 1 was off, so it simply came on.

Adding 1: the bits on the right that were on went off, and the next bit came on. That is a carry, like 9 + 1 = 10.

All 8 bits are on: 255, the biggest number 8 bits can show. To go higher you need one more bit.

Yes, that is one of the numbers to make. Now try another.

You made every number in the row.

A new pattern! Keep switching to find the others.

You have found that pattern already.

You found them all: 8 bits make 16 different patterns.

Octal number system

The octal number system is the base-8 number system. It uses eight digits, 0 to 7; there is no 8 or 9 in octal, just as decimal has no single digit for ten. Its place values are powers of 8: 1, 8, 64, 512… Examples of octal numbers: (207)₈, (5706)₈, (601022)₈.

Hexadecimal number system

The hexadecimal number system (often just hex) is the base-16 number system. It needs sixteen symbols, but we have only ten digits, so after 0 to 9 it uses the six letters A, B, C, D, E and F for the values 10 to 15. (“Hexa” means six and “decimal” ten: six plus ten.) Its place values are powers of 16: 1, 16, 256, 4096… Examples of hexadecimal numbers: (8F5)₁₆, (AC4)₁₆, (B52)₁₆, (ACD)₁₆.

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Number system chart

The chart puts the four systems side by side: each one’s base, and the digits it uses.

Number system Base Symbols (digits) used
Binary 2 0, 1
Octal 8 0, 1, 2, 3, 4, 5, 6, 7
Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Notice the pattern: the digits of base b run from 0 to b − 1. Binary’s biggest digit is 1, octal’s is 7, decimal’s 9 and hex’s F (15).

What is the base of the binary number system?

Pick an answer to see why.

Which of these is a correct octal number?

Pick an answer to see why.

Application of number system conversion

Changing a number from one number system to another, number system conversion, is used wherever people work with computers and digital devices:

  • Computing: computers store and process everything in binary, so programmers convert between binary, decimal, octal and hexadecimal to understand what is stored.
  • Digital electronics: digital logic design, the designing of circuits and chips, works in binary, and engineers write long patterns of bits in hexadecimal.
  • Networking: every device on a network has an IP address. An IPv4 address such as 192.168.1.10 is four bytes written in dotted-decimal notation, each part 0 to 255; a newer IPv6 address is written in hexadecimal, like 2001:db8::8a2e:370. A network card’s MAC address is written in hex too.
  • Web pages and graphics: colors are written in hex: in #FF8800, red is FF (255), green 88 (136) and blue 00 (0), an orange.
  • Cryptography, graphics and signal processing use binary and hex to represent data compactly.

Anyone who works with digital information meets these number systems, so knowing how to convert between them is essential.

2.2 Binary calculation

Computers do all their arithmetic in binary. There are four main types of binary calculation:

  • i.binary addition
  • ii.binary subtraction
  • iii.binary multiplication
  • iv.binary division

The good news: they are done exactly like the same sums in decimal, in columns from the right. Only the tables are smaller, because there are only two digits.

Binary addition

Binary numbers are added the same way as decimal numbers. In decimal, 9 + 1 = 10: you write 0 and carry 1, because ten doesn’t fit in one digit. In binary the same thing happens much sooner: 1 + 1 = 2, and 2 doesn’t fit in one binary digit, so it is written 10 (one two and no ones): write 0, carry 1.

A B A + B
0 0 0
0 1 1
1 0 1
1 1 0, carry 1 (that is, 10)

When a column also has a 1 carried into it, you may have 1 + 1 + 1 = 3, which is 11 in binary: write 1, carry 1.

Steps of binary addition:

  1. Write the numbers one under the other, lined up on the right, as you would in decimal.
  2. Start with the column on the right.
  3. Add the digits of that column (and any carry) by the rules above. Write the sum’s right digit under the column and carry 1 to the next column if there is one.
  4. Move one column to the left and add it the same way, with its carry.
  5. Repeat until every column is added. A carry out of the last column is written as a new digit on the left.

Try it

Adding column by column

This is the first example. Press Add column by column and watch each carry move left. Then tap the bits to make your own sums; the decimal line underneath checks the answer.

168421 11 + 10001
In decimal
12 + 5 = 17
Answer in 5 bits
17

Tap the bits to change the two numbers. Each column is added like on paper: 1 + 1 = 10, so write 0 and carry 1.

The answer, 17, needs 6 bits, but there are only 5. The extra 1 falls off the left end and is lost, so 5 bits show 17. This is overflow.

Column worth 32: 0 + 0 = 0. Write 0, nothing to carry.

Column worth 32: the bits add up to 1. Write 1, nothing to carry.

Column worth 32: 1 + 1 = 2, which is 10 in binary. Write 0, carry 1 to the next column.

Column worth 32: 1 + 1 + the carried 1 = 3, which is 11 in binary. Write 1, carry 1.

What is (111)₂ + (1)₂?

Pick an answer to see why.

Binary subtraction

Binary numbers are subtracted the same way as decimal numbers, in columns from the right. Three columns are easy. The fourth, 0 − 1, can’t be done as it stands, so you borrow 1 from the next column on the left.

A B A − B
0 0 0
1 0 1
1 1 0
0 1 1, borrowing 1 from the next column on the left

Why is 0 − 1 equal to 1 after borrowing? In decimal, 1 borrowed from the tens is worth ten ones. In binary, 1 borrowed from the next column is worth two of this column, because each place is worth twice the one to its right. So the column becomes 2 (written 10), and 2 − 1 = 1. The column you borrowed from goes down by 1.

When the next column is 0, the borrow passes through it, as when you take 1 from 1000 in decimal (999 is left): every 0 on the way becomes 1. Try it here.

Try it

Borrowing column by column

Press Subtract column by column. A digit written above a column, the old one struck out, is what it holds after borrowing: 10 (two) where it borrowed, 0 where it lent. Then tap the bits to make your own.

32168421 01101110 − 011011
In decimal
40 − 13 = 27
Check by adding
11011 + 1101 = 101000

The second number is bigger than the first, so the answer would be negative. Make the first number the bigger one.

Tap the bits to change the numbers, then go column by column. A digit written above, with the old one struck out, is what that column holds after borrowing.

In binary subtraction, what is 0 − 1?

Pick an answer to see why.

Binary multiplication

Binary multiplication is the easiest of all, because the times table has only four lines:

A B A × B
0 0 0
0 1 0
1 0 0
1 1 1

Any binary digit multiplied by 0 gives 0, and multiplied by 1 gives itself. So long multiplication in binary is just copying: for each digit of the bottom number, from the right, write the top number (if the digit is 1) or a row of 0s (if it is 0), each row moved one place further left. Then add the rows.

Look at the rows: moving a binary number one place left, with a 0 on the right, doubles it, as putting a 0 after a decimal number multiplies it by ten. Processors multiply by 2, 4 or 8 this way, by shifting the bits, one of the fastest things they can do.

Binary division

Binary division is long division, as in decimal, and it is simpler: at each step the divisor goes into the part you are looking at either once (1) or not at all (0). If it goes, subtract it in binary and bring down the next digit.

What is the result of multiplying any binary digit by 0?

Pick an answer to see why.

An old printed page in French: down the left, the numbers 0 to 32 written in 0s and 1s beside their decimal values; on the right, small sums worked in binary
Figure 2.3 A page of Leibniz’s paper of 1703: down the left, the numbers 0 to 32 in binary; on the right, examples of adding, subtracting, multiplying and dividing in binary. Photo: Gottfried Wilhelm Leibniz, Public domain

A real computer adds one more twist: it keeps each number in a fixed number of bits, so an answer can be too big to fit (overflow), and negative numbers need a way of being written. Both come in other grades.

2.3 Number conversion

People use the decimal number system; computers work in binary, and programmers write binary in octal or hexadecimal, which are shorter. Binary numbers are long and hard for us to read, and a computer can’t work in decimal directly, so we need methods to convert a number from one number system to another. Figure 2.4 shows which method to use for which.

Decimalbase 10Octal÷ 8× powers of 8Binary÷ 2× powers of 2Hexadecimal÷ 16× powers of 16groups of 3 bitsgroups of 4 bits÷ out of decimal: divide by the base againand again; read the remainders upwards× into decimal: digit × place value, then add
Figure 2.4 Which method for which conversion. Out of decimal into any other base: divide (÷). From any base into decimal: multiply each digit by its place value and add (×). Between binary and octal or hexadecimal there is a shortcut: groups of 3 or 4 bits.

Decimal to binary, octal and hexadecimal

All three use the same method: divide by the base again and again, and keep the remainders.

Decimal to binary

To convert a decimal number to binary:

  1. Divide the decimal number by 2 and write down the remainder.
  2. Divide the quotient by 2 again, and write down that remainder.
  3. Repeat until the quotient becomes 0.
  4. Write the remainders from the bottom to the top.

In exams this is written as a short ladder: the base on the left, each quotient under the number it came from, and its remainder beside it.

Decimal to octal

The same steps, dividing by 8: divide the decimal number by 8 and write down the remainder; divide the quotient by 8 again; repeat until the quotient becomes 0; write the remainders from bottom to top.

Decimal to hexadecimal

The same steps, dividing by 16. A remainder can now be anything from 0 to 15: write a remainder of 10 to 15 as its letter, A to F.

Try it

Divide and read upwards

Type a number and choose the base. The ladder is written as in the exam, and underneath, the answer is turned back into decimal to check it. Work the exercise on paper first, then check here.

2 46
2 23 0
2 11 1
2 5 1
2 2 1
2 1 0
0 1

Read the remainders upwards, from the bottom.

Place 2⁵
32
2⁴
16
2³
8
2²
4
2¹
2
2⁰
1
Digit 101110 Worth 3208420
Place 0
0
0
0
0
0
0
0
0
0
0
0
Digit 000000 Worth 000000
Place 2⁵
32
2⁴
16
2³
8
2²
4
2¹
2
2⁰
1
Digit 101110 Worth 3208420
Change it to base
Answer
(46)₁₀ = (101110)₂
Check
the Worth row adds up to 46

Binary, octal and hexadecimal to decimal

Going the other way, multiply and add: write each digit’s place value over it, multiply each digit by its place value, and add the products.

Binary to decimal

  1. Multiply each binary digit by its place value, the powers of two from the right: 2⁰, 2¹, 2², 2³, 2⁴ … (1, 2, 4, 8, 16 …).
  2. Add all the products of Step 1. The total is the decimal number.

Octal to decimal

  1. Multiply each octal digit by its place value, the powers of eight: 8⁰, 8¹, 8², 8³, 8⁴ … (1, 8, 64, 512, 4096 …).
  2. Add all the products. The total is the decimal number.

Hexadecimal to decimal

  1. Multiply each hexadecimal digit by its place value, the powers of sixteen: 16⁰, 16¹, 16², 16³, 16⁴ … (1, 16, 256, 4096, 65536 …). Use a letter’s value: A = 10 … F = 15.
  2. Add all the products. The total is the decimal number.

In changing (93)₁₀ to octal, 93 ÷ 8 = 11 remainder 5, 11 ÷ 8 = 1 remainder 3, and 1 ÷ 8 = 0 remainder 1. What is the answer?

Pick an answer to see why.

Decimal, octal, hexadecimal and binary from 0 to 15

Learn this table: the conversions between binary, octal and hexadecimal below are read straight from it.

Decimal Hexadecimal Octal Binary
0 0 0 0
1 1 1 1
2 2 2 10
3 3 3 11
4 4 4 100
5 5 5 101
6 6 6 110
7 7 7 111
8 8 10 1000
9 9 11 1001
10 A 12 1010
11 B 13 1011
12 C 14 1100
13 D 15 1101
14 E 16 1110
15 F 17 1111

Notice: every hex digit fits in four bits (F is 1111), and every octal digit fits in three bits (7 is 111). That is not luck: 16 = 2⁴ and 8 = 2³.

Binary to hexadecimal and back

Because one hex digit is exactly four bits, you can change between binary and hexadecimal without going through decimal at all.

Binary to hexadecimal:

  1. Split the binary digits into groups of four, starting from the right. If the last group on the left is short, fill it with 0s in front (they change nothing).
  2. Write the hexadecimal digit for each group of four.
  3. Write the result with base 16.

Hexadecimal to binary:

  1. Write each hexadecimal digit as its group of four bits.
  2. Write the result with base 2 (0s at the very front may be dropped).

Binary to octal and back

The same shortcut works for octal with groups of three bits, because one octal digit is exactly three bits.

To go between octal and hexadecimal, pass through binary: octal to binary in threes, then binary to hex in fours.

Try it

Bits in groups

Tap the bits. Hex groups them in fours and Octal in threes, always from the right; each group is read as one digit.

B 5
Binary
(10110101)₂
Hexadecimal
(B5)₁₆
Decimal
(181)₁₀

Each group of four bits, counted from the right, is one hex digit, from 0000 = 0 to 1111 = F.

Each group of three bits, counted from the right, is one octal digit, from 000 = 0 to 111 = 7. A short group on the left is filled with 0s.

How many binary digits does one hexadecimal digit stand for?

Pick an answer to see why.

Exercise

1. Choose the correct option

i. What is the result of the binary addition 1101 + 1011?

Pick an answer to see why.

ii. When adding two binary numbers, what is the carry in binary addition?

Pick an answer to see why.

iii. In binary multiplication, what is the result of multiplying any binary digit by 0?

Pick an answer to see why.

iv. What is the base of the octal number system?

Pick an answer to see why.

v. What is the binary equivalent of the octal number 64?

Pick an answer to see why.

vi. In the hexadecimal system, what does the symbol A represent?

Pick an answer to see why.

2. Answer these questions

a.

What is a number system?

Answer
b.

Define the base or radix of a number system.

Answer
c.

List the different types of number systems.

Answer
d.

What is the hexadecimal number system? Write the symbols used in it.

Answer

3. Calculate the following as indicated

a.

Perform the following binary additions:

  • i.(11110)₂ + (1001)₂
  • ii.(1011)₂ + (1001)₂
  • iii.(101011)₂ + (11011)₂
  • iv.(1010)₂ + (110)₂
  • v.(101001)₂ + (1110)₂
  • vi.(100001)₂ + (100011)₂
  • vii.(100111)₂ + (11010)₂
  • viii.(110001)₂ + (100101)₂
Answer
b.

Perform the following binary subtractions:

  • i.(1100)₂ − (1001)₂
  • ii.(1001)₂ − (110)₂
  • iii.(11101)₂ − (1010)₂
  • iv.(101100)₂ − (10011)₂
  • v.(11111)₂ − (10110)₂
  • vi.(110011)₂ − (10100)₂
  • vii.(100100)₂ − (1110)₂
  • viii.(1000001)₂ − (10101)₂
Answer

4. Convert the given numbers as indicated

a.

Decimal to binary:
i. (56)₁₀ ii. (78)₁₀ iii. (123)₁₀ iv. (345)₁₀ v. (540)₁₀ vi. (572)₁₀ vii. (546)₁₀ viii. (1098)₁₀ ix. (2103)₁₀ x. (445)₁₀

Answer
b.

Binary to decimal:
i. (1101)₂ ii. (1010)₂ iii. (10010)₂ iv. (10110)₂ v. (101001)₂ vi. (11100111)₂ vii. (111100)₂ viii. (10010011)₂ ix. (1011100)₂ x. (100110)₂

Answer
c.

Decimal to octal:
i. (69)₁₀ ii. (216)₁₀ iii. (767)₁₀ iv. (79)₁₀ v. (443)₁₀ vi. (413)₁₀ vii. (765)₁₀ viii. (1334)₁₀ ix. (1825)₁₀ x. (2783)₁₀

Answer
d.

Octal to decimal:
i. (124)₈ ii. (242)₈ iii. (333)₈ iv. (763)₈ v. (103)₈ vi. (451)₈ vii. (3401)₈ viii. (1045)₈ ix. (437)₈ x. (611)₈
The textbook prints ix. as (438)₈, but 8 is not an octal digit, so the book’s number doesn’t work; (437)₈ is used here.

Answer
e.

Decimal to hexadecimal:
i. (55)₁₀ ii. (540)₁₀ iii. (225)₁₀ iv. (880)₁₀ v. (2046)₁₀ vi. (2024)₁₀ vii. (6678)₁₀

Answer
f.

Hexadecimal to decimal:
i. (56)₁₆ ii. (67)₁₆ iii. (558)₁₆ iv. (B74)₁₆ v. (20D3)₁₆ vi. (DEF)₁₆ vii. (6E3)₁₆ viii. (63F)₁₆

Answer
g.

Binary to hexadecimal:
i. (1000110)₂ ii. (11001)₂ iii. (1111000)₂ iv. (11110000111)₂ v. (101010110)₂ vi. (1110010110)₂ vii. (11011001)₂ viii. (1001100)₂

Answer
h.

Hexadecimal to binary:
i. (D4)₁₆ ii. (643)₁₆ iii. (189)₁₆ iv. (2BF)₁₆ v. (A9F)₁₆ vi. (FACE)₁₆ vii. (FB4)₁₆ viii. (1B2)₁₆

Answer

A companion to your textbook, not a replacement for it: study from the book your school uses, and where the two differ, follow your teacher. Found a mistake? Please tell us.