GST105 Part4
GST105 Part4
Just as humans have languages with which they communicate, computers have a language that
they work with; the Binary number system. Binary as a mathematical number system is a way
of counting comprising of two numbers, 0 and 1. Our conventional way of counting is in tens,
that is, the decimal number system, probably because we have ten fingers to represent ten
numbers. In the same context, the computer is made up of switches which have only two states;
ON and OFF in which it represents information.
Electricity can flow through switches: if the switch is closed, the electricity flows; if the switch
is open, the electricity does not flow. To process real-world data in the computer, we need a
way to represent the data in switches. Computers do this representation using a binary coding
system. Information that can be represented in a computer include characters, integers, fixed
point and floating point numbers, pictures, videos, sounds and programs.
A byte is a unit of information built from bits; one byte equals 8 bits.
Bytes are combined into groups of 1 to 8 bytes called words.
A byte is a sequence of 8 bits, i.e., 28 = 256 possible different values for a byte.
A single byte can represent many different kinds of data. What data it actually represents
depends on how the computer uses the byte.
There are a number of standards across the globe for character codes. The code called ASCII
(pronounced "AS-key"), which stands for American Standard Code for Information
Interchange, uses 7 bits for each character. Since there are exactly 128 unique combinations
of 7 bits, this 7-bit code can represent only characters. A more common version is ASCII-8,
also called extended ASCII, which uses 8 bits per character and can represent 256 different
characters. For example, the letter C is represented by the decimal value 67.
Other codes include the ANSI (American National Standards Institute), Unicode, EBCDIC etc.
1
GST105 INTRODUCTION TO COMPUTER SCIENCE 2018/2019
LECTURE NOTE (PART 4)
As languages developed, humans began using symbols and words for numbers. The Chinese
as early as 1400BC introduced a bamboo stick decimal numbering system and developed the
abacus on this system.
Later these designations were replaced in the west by the Hindu Arabic symbols for 1 through
9. But the concept of zero which the Chinese used blank space for was replaced with the symbol
0 in the Hindu-Arabic system, making it ten symbols, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The reason for
the use of ten symbols by the Hindu-Arabic system is clearly because of humans having 10(ten)
fingers on their two hands.
This explains why the Hindu-Arabic system, that is, the decimal system is the commonest
numeral system. It is the modern human counting system which is based on grouping of tens
and it is called base-10, the base-10 system uses ten different numeral symbols (0, 1, 2, 3, 4, 5,
6, 7, 8, 9,) to represent all numbers.
The Yuki Indians of California used a base-8 numeral system; instead of basing their system
on the number of human fingers, they used the spaces between the human fingers. Also the
Ancient Mayans used a base-20 system. They counted with the digits on their hands and feet
because they lived in a hot climate where people didn’t wear closed toe shoes.
We can also count in numbers larger than ten. If we count in sixteen, the digits are 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, A, B, C, D, E, F, with A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. The largest
digit is F. Other letters can also be used to denote numbers greater than 10 besides A, B, C, D,
E, F.
2
GST105 INTRODUCTION TO COMPUTER SCIENCE 2018/2019
LECTURE NOTE (PART 4)
In such a system like on or off, of an electrical appliance, one cannot have “neither on nor off”,
it must be “on or off”, in such case base two comes into play where 0 may stand for OFF and
1 may be for ON.
The binary system and other extensions of the binary system are used in computing since data
is represented inside the computer in arrays of 0s and 1s only. Inside the computer, pulses of
electricity represent data by combination of 0s and 1s. Most often 1 denotes circuits which are
On and 0 for a circuit which is Off.
To show that a number is binary, the binary number is followed with a little 2 (as subscript).
Example
Convert each of the following numbers in the given base to base ten.
a) 5368 (b) 110112 (c) 12435 (d) B3AC16
Solution
a) 5368
Using the expanded notation
5368 = 5 x 82 + 3 x 81 + 6 x 80
= 5 x 64 + 3 x 8 + 6 x 1
= 320 + 24 + 6 = 350ten
b) 110112
Using expanded notation
110112 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20
= 1 x 16 + 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1
= 16 + 8 + 0 + 2 + 1
= 27ten
3
GST105 INTRODUCTION TO COMPUTER SCIENCE 2018/2019
LECTURE NOTE (PART 4)
In method of successive division, 2 is used to continuously divide the base ten number and the
remainders collected from downwards. The division ends when the divisor (2) becomes greater
than the dividend, in this case the quotient is zero and the remainder becomes the last dividend.
The other method, the use of the correct place values in base two, involves choosing the
appropriate powers of 2 which when added, gives the number in base ten.
This course treats just the method of successive division.
Example: Convert the following base ten numbers into base two using the methods of
successive divisions.
Solution
Using the method of successive division
2 17
2 8R1
2 4R0
2 2R0
2 1R0 10001two
0R1
4
GST105 INTRODUCTION TO COMPUTER SCIENCE 2018/2019
LECTURE NOTE (PART 4)
Conversion from Base Ten to Any base other than Base Two
The change a whole number in base ten to any other base outside base two, the method of
successive division is used.
Example:
Convert the following base ten numbers to the indicated base in bracket
i) 75 (base five) (ii) 73 (base eight)
iii) 324 (base sixteen) (iv) 96 (base six)
Solution
Using the method of successive division in each case
i)
5 73
5 14 R 3
5 2R4 = 243five
0R2
ii)
8 73
8 9R3
8 1R1 = 111eight
0R1
iii)
16 324
16 20R 4
16 1R4
0R1 = 144sixteen
iv)
6 96
6 16 R 0 = 240six
6 2R4
0R2
5
GST105 INTRODUCTION TO COMPUTER SCIENCE 2018/2019
LECTURE NOTE (PART 4)
Example: (a) Change 134five to base two (b) Change 3245six to base 9.
Solution
a) 134five is first converted to base ten using the expanded notation
1345 = 1 x 52 + 3 x 51 + 4 x 50
= 1 x 25 + 3 x 5 + 4 x 1
= 44ten
Now 44ten is converted to base 2 using successive division
2 44
2 22 R 0
2 11 R 0
2 5 R1
2 2 R1
2 1 R0
= 101100two
0 R1
134five = 101100two
3245six = 10119