Chapter 3
Chapter 3
Investigates how data are represented and exploits them in arithmetic and
logic operations.
Analyzes how metric data are represented in computers.
Numbers are used to express the quantitative value of something. Basic unit used to create a number can be
called a digit. All the numbers used by man are formed by digits built on symbols different from one another.
Any integer set that can represent any finite value can be called a Number System. For example, the decimal
number system is created by a set of numbers from 0 to 9.
When typing letters or words using the computer, these words or letters are represented by the computer as
numbers it can understand. While this group of numbers that the computer can understand is called a 'Number
System' the limited number of numerals in the number system called digits. The value of these numbers
(numerals) depends on the position they occupy within the number.
While the concept of number system was present in the 'Abacus ' considered as the first calculating machine
of the world, it has progressed up to the computer of today.
Unit - Unit is a single object. For instance, a mango, a Rupee, and a day can be considered a unit.
Number - A number is a symbol which represents a unit or quantity.
Base / Radix - A number of symbols used in a number system is called the base/radix. The base of any
number system is indicated in decimal numbers.
Decimal Number System consists of digits from 0 to 9. Normally, the base value of decimal numbers are not
mentioned, but for the other numbers the base value has to be mentioned. The digits that are used in the
decimal number system are as follows;
Example
Let us consider how the number 25 is formed. 25 is formed with the addition of 20 and 5.
25 = 20 + 5
= ^2 « 10& ¬ ^5 « 1&
= ^2 « 101& ¬ ^5 « 100&
These positional values such as 100, 101, 102 are called Weighting Factors of decimal number system. This
number can be shown on a counting frame.
2
Integer
Integers are number set. Natural numbers (0,1,2,3…) and (-1,-2,-3….) are integers. Neither decimal numbers
nor fractions are integers.
Eg: 5, 75, -85
7632135 763.2135
1794821 179.4821
9426956 942.6956
.
In fixed point numbers dot( ) needs to be same place.
A = 1.2345670 x 105
B = 0.0056789 x 105
1.2402459 x 105
3
The digits for the binary number system is given below.
Binary number
representation.
The Binary number system is very important in computing and it contributes in the representation of a bit; the
basic measuring unit of the computer. The smallest value and the highest value which can be seen in this
number system is 0 or 1 respectively. This smallest value is called Bit
Computer represents data in two signal states. There are two Voltage levels for these
two symbols. One is named as the high voltage level and the other is named as low
voltage level. ''0'' and ''1'' digits respectively represent these low and high voltage
levels in a circuit. Thus, ''1'' and ''0'' status are equal to the “On” and “Off” states of an
electronic circuit. Any data in the world can be represented on the computer using
these two digits.
According to the Figure given below, when data stored in Secondary Storage is sent to the Main Memory and
when it is sent to the Central Processing Unit from there, that data are converted to a binary code.
4
Let us consider the instance where Binary numbers
are used for computer colours. Any colour can be
made with the combination of different degrees of
red, green and blue.
The values such as 80,81,82,83 … are called the weighting factors of the octal number system. This number can
be represented as given below in a base eight counting frame.
5
Hexa-Decimal Number System
The computer uses binary numbers and it is difficult for human beings to read them. Hence, the hexadecimal
number system is used as it is easier for humans to use. Normally, calculations are performed using the ten
fingers of the hands. Just imagine you have sixteen fingers on your hands. Then you can use sixteen numbers
to count. In the hexadecimal number system, ten digits are used from 0 to 9 and for the other 6 digits, A, B, C,
D, E and F symbols are used. Here, A, B, C, D, E and F are used to represent 10, 11, 12, 13, 14 and 15.
When F the largest number of hexadecimal number system, is expressed in binary form, it can be indicated
with 4 Bits. Thus, instead of using a binary number with 4 Bits, a single number in hexadecimal number
system can be used. For example, Hexadecimal numbers are used to represent memory addresses of the
computer.
You can see code “# 871F78” related to the dark purple colour shown in Figure 3.4. Here the value of the
colour is started with “#” symbol. The colour value is indicated in the computer in hexa decimal numbers.
Thus, the code for dark purple in the above example is “# 871F78”. R,G,B values of this can be indicated
from 0 to 255 in decimal numbers. If “#’ or “&H” (ampersand) symbol is used in front of the value of any
value, it is a hexa decimal number. Given below in Table are the hexa decimal values and RGB values of dark
purple colour.
6
Relationship among Decimal, Binary, Octal and Hexadecimal
There are two seperate methods to find the most and least significant values of decimal numbers and whole
numbers. When a whole number is read from left to right, the number in the right most end is the least
significant positional value and the number in the left most end which is not 0 is the most significant
positional value.
7
Activity
Find the most significant digit and the least significant digit of the following numbers.
(i) 5687010 (ii) 154.0110 (iii) 23.0808 (iv) AD 23916 (v) 0.001102
Only the Binary Number System is used to find the most significant bit (MSB) and the least significant
bit(LSB). There are two ways to find this using decimal numbers and whole numbers.
In a whole number, read from left to right, the value in the right extreme is the least significant bit and the
value in the left extreme which is not 0 is the most significant bit. In binary decimal numbers, the value in the
right extreme of the decimal point which is not 0 is the least significant bit and the value in the left extreme of
the decimal point which is not 0 is the most significant bit.
Activity
Find the most significant bit and the least significant bit of the following numbers.
(i) 10002 (ii) 0111012 (iii) 0.110012 (iv) 1.00102 (v) 0.001102
All the data we input to the computer is taken by it as digits of binary number system; 0 and 1. Hence, the
knowledge to convert a base ten number to another base is important. Here in this chapter, conversion of a
decimal number to a binary number, octal number and a hexadecimal number is discussed.
8
Conversion of Decimal Numbers to Binary Numbers
When a decimal number is converted to a binary number, the decimal number can be divided by two until the
remainder is 0 and the remainder of the division can be written on the right side. After that, write all the
remainders from the bottom to top to build the number.
Activity
Convert the following decimal numbers
to binary numbers.
(i) 15510 (ii) 47210 (iii)116310
Activity
9
Converting Decimal Numbers to Hexadecimal Numbers
Here, divide the number by 16 until the remainder is 0 and write down the remainders from bottom to top.
Activity
10
Activity
From the digits used in the octal number system; 0, 1, 2, 3, 4, 5, 6, and 7, the largest digit is 7. We can
indicate digit 7 as 1112 in binary form. Thus 7; the largest digit in the octal number system, can be indicated in
a binary form with 3 digits. Likewise all the digits in the octal number system can be indicated in the three
digit binary form. Given below in Table are the binary forms of the digits used in eight base (octal) number
system.
As per the above table, three bits are used when indicating an octal number in binary form. (8 = 2 3)
Let us consider how a binary number is converted to an octal number.
Example
Converting 10111012 to an octal number.
First, divide the number into three bits from the right corner to the left corner. If the last cluster in the
left corner does not consist of 3 bits, add 0s to complete.
Write each octal number separately for each cluster.
Then write these clusters in octal digits.
Write these digits in order from the left corner to the right corner.
Activity
11
Converting Binary Numbers to Hexadecimal Numbers
From the symbols used in the hexadecimal number system, the value represented by “F” possesses the largest
numerical value. This can be indicated as a four-bit binary number; 11112. Thus, all the digits in the
hexadecimal number system can be indicated as four-bit binary numbers. Given below in Table are the binary
numbers for the digits used in the hexadecimal number system.
As shown in the table above Table, four bits are used to indicate a hexadecimal number in binary form. (16 =
24)
Example
Converting number 101102 to a hexadecimal number.
• First, divide the number into four-bit clusters from the right corner to the left corner.
• Write hexadecimal numbers separately for each cluster.
• Write these numbers in order from the left corner to the right corner and write down the base.
12
Example
Converting number 101110111002 to a hexadecimal number.
Activity
Activity
Convert the following octal numbers to decimal numbers.
(i) 2308 (ii) 7458 (iii) 20658
13
Converting Octal numbers to Binary Numbers
We have learned above that an octal number can be indicated in three digits when it is converted to a binary
number. Thus, each digit in octal numbers should be written in three digits when it is converted to base two.
Example
Converting number 4578 to a binary number.
Firstly, write each digit in octal number in three bits.
Secondly, write down all the bits together to get the binary number for the octal number.
Activity
Example
Converting number 10578 to a hexadecimal number.
• First, write each digit in octal number in three bits.
• Divide the binary number you get into four-bit clusters from the right corner to the left corner.
• Write the related hexadecimal number for each cluster.
Activity
14
Converting Hexadecimal Numbers to Decimal Numbers
Activity
You have learnt earlier that any symbol in a hexadecimal number can be written in a four-bit binary number.
Thus, when a hexadecimal number is converted to a binary number, each digit in that number should be
indicated in a four-bit binary number.
15
Activity
Convert the following hexadecimal numbers to binary numbers.
(i) 7816 (ii) B2C16 (iii) 4DEF16
First, the hexadecimal number should be converted to a binary number and then it should be converted to an
octal number.
Activity
Activity
1. Consider number “23y”. Here, ‘y’ is the base of the number system. From the number systems you have
learned, as to which number system “23y” belongs.
2. Convert the decimal number 8310 to a binary number. Show steps.
3. Convert the binary number 101101112 to an octal number. Show steps.
4. Convert the hexadecimal number 23D16 to a binary number.
5. Fill in the blanks in the table given below.
16
Conversions between number systems
By adding all the numbers after multiplying each and every digit in the binary number with its relevant
place value, the corresponding decimal value of that number is found.
5. Fractions to Octal
a. Multiply the given decimal fraction by 8.
b. Multiply the decimal by 8 until it becomes 0.
c. Write from the beginning to end, the values in front of the
decimal point.
17
7. Conversion of a binary number into a octal number
First, beginning from the decimal point of the binary number from groups of three numerals each
starting from the decimal point moving left.
If a group has less than three numerals add a “0” in front to form a group of three numerals.
In making the fractional part octal, form groups of three numerals each, moving right from the
decimal point.
If the number of numet=rals in a group is less than three add a “0” to the end complete the group.
Write the octal number relevant to each group.
18
According to the above figure, when you enter a data to the computer, it converts the data to different patterns
made of 0 and 1. Thus, binary codes are used when storing numeric, alphabetic, special character, images and
sounds in internal storage devices of computers.
In the beginning of the lesson, when you type ‘A’ on the keyboard, the code you get for ‘A’ is the bits pattern
1000001 (the binary code of letter ‘A’). The number of bits used is 7. Thus, a combination made of a bit
pattern is used to represent each data and the bits used for each code is different. Following are
different coding systems used.
This coding system was used in the early stages of computing. In this system one digit is represented by 4
bits. This is used only to represent decimal numbers. Sixteen symbols (24 = 16) can be represented in this
system. The blow table shows the BCD codes for the 10 digits from 0 to 9.
Activity
Write the BCD values for the decimal values given below.
(i) 302 (ii) 2136 (iii) 17295
Initially ASCII coding system used 7-bit binary digit. 128 characters can be represented using this coding
system. ASCII is used to represent text.
ASCII system is designed and approved by ANSI (American National Standard Institute).
Example
• Text
When the word ‘School’ is entered into the computer through the keyboard, write down how it is understood
by the computer.
First, write the decimal numbers for the symbols.
S - 83 c - 99 h - 104 o - 111 l – 108
19
Write the associated code
S c h o o l
101001111000111101000110111111011111101100
Activity
Unicode System
20
Example
Picture and Graphic Data
Given below is a close up or a highly enlarged image of
photograph. A photograph consists of pixels (dots) made
of different colours in big grid. Computer graphic data
such as pictures, frames of a movie or frames of an
animation consist of various colours. The picture given
below consists of a number of different colours.
Sound
As shown in the figure below is the sound emitted from a speaker is normally represented as analog waves.
However, all data in computer are digital data and those are made of bytes. Hence, sound which comes as a
analog data is converted to a digital data. Thus, a sound is also represented in a bits pattern made of 0s and 1s
in a computer.
By this coding system, codes are classified to represent characters of all the international languages. The
institution which initiated is the International Standard Institution and Unicode Consortium. Unicode is
largely used in designing websites and newspapers.
Activity
1. If ‘A’ character is represented as 1000001 in ASCII system, what is the ASCII code for letter ‘F’?
2. What is the largest number presented in BCD (Binary Coded Decimal)?
3. What is the minimum number of bits required to present a hexadecimal number?
4' If 10000102 represents “B” in ASCII code, what is the ASCII code for letter “L”?
5. What are the coding systems used in computers? Explain the need to use such coding systems.
21
ASCII and EBCDIC codes for characters and related decimal, octal and hexadecimal numbers
22
23
ASCII and EBCDIC values related to letters - Unicode for Sinhala and Tamil letters
24
Uses basic arithmetic and logic operations on Binary, Octal and Hexadecimal numbers.
In number system basic operators are addition, subtraction, multiplication and division. For these operators
always used decimal number system as same as other number systems can use these operators. The most
important thing is to understand the number system and nature of the base value. That means the maximum
value and the movements to the next weighting point.
Eg:
1. 7 + 5 = 12, here two ones’ set and one tens’ set are included. This two ones’ set is placed in 100th
weighting point and one tens’ set goes to next weighting point 101 as 1.
2. 6 + 8 =14 and that one tens’ set is 15 now. Here also one tens’ set and remainder is 5. This remainder
5 placed to 101 and one tens’ set goes to next weighting point 102 as 1.
Like above example always if tens’ set are available, that goes to next weighting point (left side) and
remainder is placed in the same position.
In here tens’ set are taken because 10 base number system used for the calculations. If the base is 8 eights’ set,
base is 2 twos’ set and base is 16 sixteens’ sets needs to calculations.
In binary calculations twos’ sets, octal calculation eights’ sets and hexadecimal calculations sixteens’ sets
need to be placed to left side.
Exercise
Binary Addition
Addition of binary values same as adding decimal values. In binary number system, one place maximum
value is 1. If adding value is more than 1 that value goes to the left hand place. There are four main situations.
02 + 02 = 02 02 + 12 = 12 12 + 02 = 12 12 + 12 = 02
25
Situation A + B Addition Carry
1 0 + 0 0 0
2 0 + 1 1 0
3 1 + 0 1 0
4 1 + 1 0 1
Eg: Remainder
Binary Subtraction
Subtraction of binary number same as decimal subtraction, big value subtract by small value from left side
need to borrow a one bit. There are four main situations here.
Binary multiplication
Multiplication of binary values same as decimal values. In here always 0 and 1 is coming as answer. There are
four main situations.
Situation A x B Answer
1 0 x 0 0
2 0 x 1 0
3 1 x 0 0
4 1 x 1 1
Binary Division
Division of binary values same as decimal values. This method is long method of division.
26
I computer programming, bit wise operation, depending on one bit or more or binary values single bit
operations can be processing.
Bitwise OR Operation
Logic NOT operations is processing and get the invert of the number.
Analyses how signed numbers are represented in computes and uses standard methods
to represent floating point numbers.
Signed Numbers
Up to here we have learnt unsigned numbers addition, subtraction and convert other base. It is very easy to
operate unsigned numbers but for the signed number representation need special procedure. The memory
range of the signed numbers in computer programs allocated one bit for the sign (+/-). This allocated bit is the
first bit, which considered as a most significant bit. When this bit becomes 1, the numbers is negative (-) value
number. When this bit becomes 0, the numbers is positive (+) value number. Other bits represent the value of
the number.
1. Signed Magnitude.
2. One’s Complement.
3. Two’s Complement.
Signed Magnitude.
Signed magnitude system, first bit is taken as sign and other bits are taken as numbers.
-1 = 10000001
+1 = 00000001
To store signed magnitude in a computer is used this 8 bit method. According to this maximum number is
27
27-1 (127)
Computer can do calculations using this method of numbers, but this method is not convenient method for all
times.
When calculating minus values adding all and put it as a minus (eg:-2 + (-3) = -5). But, when numbers are
having unequal signs, it is difficult to select the highest value. To solve this problem without getting sign
calculations are done. Then sign bit needs to place as first bit of the number.
N 8 bits number important rule is the value has only 7 bits. If 7th bit number comes to 8th bit that no need to
take.
Eg:
These numbers written as signed magnitude like, 010011112 + 001000112 = 011100102. The signed bit of
these numbers is 0. Above example is done as same as decimal calculations. But, after calculating 7th bit if the
value goes to 8th bit the value not used.
Because 8th bit represent sign bit. In this situation that bit considers as positive over flow and not write in the
first. Otherwise answer can be seen wrong.
Signed Magnitude
Signed Bit
28
One’s Complement
This method s very easy and from the hardware can easily change according to the one’s complement. And
easily get minus values. For the representation of the sign need not to keep bit. From one’s complement can
take binary number minus value and if the result MSB is 0 the value could be positive and no need to take
inverter. If the MSB is 1 that should be taken negative value.
23 = + (00010111) = 00010111
Here without 9 subtract 23, -9 add into 23. 23 can write as same it is and 9 needs to convert one’s
complement.
- One’s Complement
One’s Complement
Eg:
Complement
Two’s Complement
29
Eg: 23 and -9 adiing using two’s complement
Signed bit
Exponent
Fractional part
According to above example 17 can be written as 0.10001x25. Signed bit of this is zero(0). Because of the
number is positive value.
According to this method big numbers can be represent as floating point expression.
30