Chapter Three Number System and Data Representation

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Chapter Three

Number System and Data Representation


Objectives:-
-To know different number systems
-To know how to convert from one base to another
-To know how to apply arithmetic operation on binary number system

A number system is a set of symbols used for counting. There are various number
systems
Ex. Decimal, Binary, octal-decimal, hexadecimal etc.
For the purpose of understanding how data are represented, stored and processed in
computer, we will discuss only two of them, the Decimal and the binary number system.
There are different number systems. Some of them are:-

 Decimal number systems


 Binary number systems
 Octal number systems
 Hexadecimal number systems

Decimal number System (base 10) (Dec)

 It uses 10 symbols 0-9 to represent numbers;


 The Decimal number system is based on the ten different digits (or symbols)
0,1,2,3,4,5,6,7,8,9.
 We say it is a base ten number system
 Though it is widely used, it is inconvenient for computer to represent data. So we
need another number system.

Binary number System (base 2) (bin)

 It uses 2 symbols 0 and 1 to represent numbers;


 Binary number system is based on the two different digits; 0 and 1;
 It is important to note that every decimal number system has its equivalent binary
number;
 Conversion from binary to its equivalent decimal and from decimal to its
equivalent binary is possible;
 Operation on binary number system is also possible

Decima Binary Octal Hexadecimal

Introduction to ICT Page 1


l
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Octal number System (base 8) (Oct)


 It uses 8 symbols 0-7 to represent numbers;
 Like binary number system it is a complete number system.

Example1. 77 in octal equals 49 in decimal and 111111 in binary.


When we compare the octal with the decimal, 0-7 in octal is the same as 0-7 in decimal but 10
in octal is not the same as 10 in decimal because 10 in octal holds the position of 8 in decimal,
off course 10 in octal is the same as 8 in decimal.

Hexadecimal number system (16) (hex)

 It uses 16 symbols to represent numbers. But for the numbers greater than 15 they
represented in terms of the 16 symbols. for example the decimal number 16
represented as 10, 20 as 14, 30 as 1E and so on. These symbols are 0,1,…
9,A,B,C,D,E,F
 When we compare the hexadecimal with decimal, 0-9 in hexadecimal is the same as
0-9 in decimal but 10 in hexadecimal is not the same as 10 in decimal,
Of course 10 in hexadecimal is equal to 16 in decimal because it holds the position of 16 in
decimal.
Example
DECIMAL OCTAL BINARY HEXADECIMAL
0 0 0 0
3 3 11 3
8 10 1000 8
10 12 1010 A
16 20 10000 10

Introduction to ICT Page 2


Conversion from one Base to Another

The values that numbers have with a given number systems are largely determined by their
position. For example, the symbols 1 & 7 can represent either 17 or 71 depending upon their
relative position to one another.
The decimal number 135 may be expanded as:
2 1 0
(135) 10 = 1*10 +3*10 +5*10
 The subscript 10 is used to indicate 135 is in base 10 number system.
 The number 10 in binary is not the same as 10 in decimal because the
value of 1 in the binary is not the same as the value of the 1 in the
decimal.
 The binary number 1101 may be expanded as

3 2 1 0
(1101)2 =1*2 +1*2 +0*2 +1*2
= (1*8) + (1*4) + (0*2) + (1*1)
= 8+4+0+1
= 1310

*A number X1 X2 X3 …Xn in base M can be expanded as


n-1 n-2 n-3 1 0
(X1 X2 X3 …..Xn) M=X1*m +X2*m X3*m + …Xd-1*m +Xnm in base 10

Conversion from decimal (base 10) to other base (base M)

(Base10------------->BaseM)

 To convert a decimal number X to a number in base M, divide X by M, store the


remainder, again divide the quotient by M, store the remainder, and continue until the
quotient is 0. And concatenate (collect) the remainders starting from the last up to the
first.
Example1.Convert (56)10 to base two (binary)
X=56 M=2
(56)10 = (111000)2

Conversion from base M to base 10 (decimal)

 To convert a number X consists of digits X 1 X2 X3 …Xn in base m to decimal; simply


expand the number with base M. That is
n-1 n-2 n-3 n-i 1 0
(X1X2X3…Xn) m =X1*m +X2*m +X3*m +...+ Xi*m +… Xn-1m +Xn*m
=Y10

Example1. Convert (1001001)2 to decimal


6 5 4 3 2 1 0
=> (1*2 )+(0*2 )+(0*2 )+(1*2 )+(0*2 )+(0*2 )+(1*2 )
=> 64+8+1 = 73

Introduction to ICT Page 3


Converting decimal number with fractions to Binary.

 First change the integer part to its equivalent binary.


 Multiply the fractional part by 2 and take out the integer value, and again multiply the
fractional part of the result by 2 and take out the integer part, continue this until the product is
0.
 Collect the integer values from top to bottom & concatenate with the integer part.

Example: A) Convert (12.25)10 to binary (1100.01) 2


Solution:
B) Convert (3.1875)10 to binary (11.0011)2

Converting Binary with fraction to decimal.

To convert a binary number Y1Y2Y3Y4Yn.d1d2d3...dm to decimal first convert the integer part
to decimal by using
n-1 n-2 n-j 1 0
y1 y2 y3 y4…yn=y1*2 +y2*2 +….yj*2 +….+yn-1*2 +yn*2 =Q and convert the
fractional part to decimal by using
-1 -2 -3 -j -m
d1d2d3…dm=d1*2 +d2*2 +d3*2 +…+dj*2 +..+dm*2 =R

then decimal equivalence of y1 y2 y3 y4…..yn.d1d2…dm will be Q+R where Q is the integer


part and R is the fractional part.

Example1. Convert 11001.0101 to decimal


4 3 2 1 0
11001 = 1x2 + 1x2 +0x2 +0x2 +1x2 = 16+8+1= 25
-1 -2 -3 -4
0101 =0x2 +1x2 +0x2 +1x2
= 0+¼+0+1/16 = 0.3125
=>11001.0101 = 25.3125.
Example2. Convert 1000.1 to decimal
3
1000 = 1+2 +0+0+0=8
-1
1= 1x2 =½ = 0.5
Therefore: 1000.1 => (8.5)10

Conversion from binary (base2) to Octal (base 8) or hexadecimal


(base16) and vice versa
To convert a number in binary to octal group three binary digits together starting from
the last digit (right) and if there are no enough digits add zeros to the front end (left)
and find the corresponding Octal of each group.
Example. Convert 1001001 to octal = 1118
1001001=001,001,001
Introduction to ICT Page 4
Convert 101101001 to octal =5518
101101001 =101,101,001
To convert binary to hexadecimal group four binary digits together starting from right
and if there are no enough digits add zeros at the left.
EX. Convert 111100100 to hexadecimal Convert 111001111 to Hexadecimal
111100100 =0001 1110 0100 111001111 =0001 1100 1111
=1 14 4 =1 12 15
=1 E 4 =1 B F
= 1E416 =(1BF)16
To convert from Octal to binary, convert each octal digit to its equivalent 3 bit binary
starting from right.
EX. Convert (675) eight to binary Convert 231eight to binary

675eight =110 111 101 231eight = 010 011 001

=110111101two =10011001two

To convert from Hexadecimal to binary convert each hex. Digit to its equivalent 4-bit
binary starting from right.
Ex. Convert 23416 to binary Convert 2AC to binary
23416 =0010 0011 0100 2AC16 =0010 1010 1100
= 10001101002 =10101011002

Conversion from Octal to hexadecimal and Vise versa


To convert from Octal to hexadecimal, first we have to convert to binary and the binary
to hexadecimal. To convert from hexadecimal to Octal, first we have to convert to binary
and then the binary to Octal.
EX.1. Convert 2358 to hexadecimal Convert 1A to Octal
2388=010 011 101 1A=0001 1010
=0000 1001 1101 =000 011 010
= 0 9 13 =0 3 2
=9D16 =328

Introduction to ICT Page 5


Conversion from Binary with fraction to Octal/hexadecimal
 Group three/four digits together starting from the last digit of the integer part, and if
there is less number of digits add some zeros in the beginning.
 Group three/ four digits together starting from the first digit of the fractional part, and
if there is less number of digits add some zeros to the end.
 Covert each group of the integer and the fractional part to their equivalent
Octal/hexadecimal and collect the results by adding point (.) to separate the integer part
from the fractional part.
Ex 1:- Covert 1010.01112 to octal
Ex2:- Covert 1110101.101112 to hexadecimal

Conversion from Octal or hexadecimal with fraction to binary.


 Convert each Octal/hexadecimal digit to its equivalent 3/4-bit binary digit.
 Collect the binary sequences by separating the integer part binaries from the
fractional part binaries with point (.)

Conversion from Octal with fraction to hexadecimal


 To convert from Octal to hexadecimal, first convert the Octal to binary and then the
binary to hexadecimal

Conversion from Hexadecimal with fraction to octal


 To convert from hexadecimal to Octal, first convert the hexadecimal to binary and
then the binary to Octal.

Conversion from octal/hexadecimal with fraction to decimal.


 To convert from Octal/hexadecimal to decimal, first convert to binary and –then the
binary to decimal.

Summary of conversion from One base to another base

Introduction to ICT Page 6


From base To base Method
2 10 Expand binary number in powers of 2
10 2 Factor the decimal number by 2
2 8 Group 3 binary digits together
8 2 Each Octal digit is converted to 3 binary digits
2 16 Group 4 binary digits together
16 2 Each hexadecimal digit is converted to 4 binary digits
8 10 Go from 8…….2…….10
10 8 Go from 10 … ..2……..8
16 10 Go from 16 …….2…….10
10 16 Go from 10 …….2…….16
8 16 Go from 8 …….2…….16
16 8 Go from 16 …….2…….8

Binary Arithmetic
Computer understands only the language of binary numbers. Therefore, the machine performs
what is called binary arithmetic (binary computation).

Binary addition

Binary addition operates by the same rule as decimal addition, except that it is simpler. A carry to
the next higher order (or more significant) position occurs when the sum is decimal 2, that is,
binary 10. Therefore, the binary addition rules may be written as follows:
0+0=0
0+1=1
1+0=1
1+1=0 plus a carry of 1 into the next position
1+1+1=1 plus a carry of 1 into the next position.
The last case occurs when the two binary digits in a certain position are 1s and there is a carry
from the previous position.
Example1. 6+7 =13
110 ----> 6
+ 111 ----> 7
1101 ---->13

Example2. 19+31+10=60

10011------->19
+ 11111------->31
+ 1010------->10
111100 ------>60

Introduction to ICT Page 7


Binary Subtraction

It operates by the same rule as decimal subtraction. The rule is as follows;


0-0=0
1-0=1
1-1=0
10-1=1

Example1.
11100 28 101101 45 11001.011
- 11010 -26- 111 -7 - 111.110
00010 = 2 100110 = 38 10001.101

Binary Multiplication:

- It is a very simple process that operates by the following obvious rulers:


(a) Multiplying any number by 1 rules the multiplicand unchanged

0x1=0
1x1=1
(b) Multiplying any number by 0 produces 0

0x0=0
1x0=0
Example1.

2*3=6

2=010 {010*011=?}
3=011

Binary division
That is, the process for dividing one binary number (the dividend) by another (the divisor) is
based on the rules for binary subtraction and multiplication and Similar to decimal division
Ex 1111101 11001
11001 101
11001
11001
00000
1111101 ÷ 11001 = 101
Data representation method
We enter data into a computer or review (see) output data from a computer using the
letter of alphabet, various special symbols, and the numerals in the decimal number
system. But since computer is an electronic device, which understands electrical flow
(signal) there is no letter, symbol or number inside the computer. Computer works with
binary numbers. As a semiconductor is conducting or isn’t conducting; a switch is closed
or opened.

Introduction to ICT Page 8


So data are represented in the form of a code that can have a corresponding electrical
signal.

The most elementary form to organize data within a computer (an electronic device) is in
the form of a code which utilizes the “ON” and “OFF” states of electric switches or there
is “current” and “no current” condition of the electronic components;
We see that the nature of the electronic devices has similarity with the binary number
system in that both represent only two elementary states;
It is therefore convenient to use binary number system to represent data in a computer;
An “ON” corresponds to a 1; an “OFF” corresponds to a 0;
In the computer “ON” is represented by the existence of a current and “OFF” is
represented by non existence of current
On a magnetic disk, the same information is stored by changing the polarity of
magnetized particles on the disk’s surface.

CODING METHODS
It is possible to represent any of the character in our language in a way as a series of
electrical switches in arranged manner;
These switch arrangements can therefore be coded as a series of equivalent arrangements
of bits
There are different coding systems, which convert one or more character sets into
computer codes. Some are: EBCDIC, BCD, ASCII-7 and ASCII-8.
In all cases, binary coding schemes separate the characters, known as character set, in to
zones. Zone groups characters together so as to make the coding scheme to decipher and
the data easier to process. With in each zone, the individual characters are identified by
digit code.
EBCDIC: Pronounced as “Eb-see-dick” and stands for Extended Binary Coded Decimal
Interchange Code.
Used usually for IBM Main frame model and in similar machines produced by other
manufacturer.
It is an 8-bit coding scheme: (00000000 – 11111111)
8
It accommodates to code 2 or 256 different characters
It is a standard coding scheme for the large computers.
Coding Example:

Character zone (4 Bit) digit (4 Bit)


0-9 15 0-9
a-i 8 1-9
j-r 9 1-9
s-z 10 2-9
A-I 12 1-9
J-R 13 1-9
S-Z 14 2-9

Introduction to ICT Page 9


Character zone (4 Bit) digit (4 Bit)
a 1000 0001
b 1000 0010
A 1100 0001
B 1100 0010
0 1111 0000
9 1111 1001
BCD (Binary Coded Decimal)
BCD is one the early memory codes .it is based on the idea of converting each digit of
decimal number in to its binary equivalent.
There are two types of BCD coding techniques used before.
a) 4 bits BCD and
b) 6 bits BCD

BCD (4 -bits)
The 4 bit BCD, which represent any digit of decimal number by four bits of binary
numbers.
If you want to represent 219 using 4 bit BCD you have to say 0010 0001 1001
♦ 4 bits BCD numbers are useful whenever decimal information is transferred into or
out of a digital system. Examples of BCD systems are electronic ousters, digital
voltmeter, and digital clocks; their circuits can work with BCD numbers.
♦ BCD’s are easy for conversion but slower for processing than binary. And they
have limited numbers because with BCD we can represent only numbers 0000 for 0
and 100 for 9 and ,1010,1011,1100,1101,1110, 1111 can’t be used because 1010
represent 10 in decimal at 10 in decimal is 1010 0000 in BCD.

The BCD equivalent of each decimal digit is shown in the following table:

Decimal BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Note:
Each decimal digit is represented in BCD by 4 bits.

Example:
Convert 4210 in to BCD

Introduction to ICT Page 10


Solution:
410=0100 in BCD
210=0010 in BCD
4210=0100 0010
4 2

= 01000010 in BCD

Note
Since 4 bits are used to represent a character, altogether only16 (24) configuration
is possible. Thus instead of using 4 bits with only 16 possible characters computer
designers commonly use 6 bits to represent characters in BCD. Now it is possible
to represent 64(26) characters.
Note:
Since we use 4 bits in BCD , altogether 16(24) configuration is possible

Activity
State the possible combinations of bits that can be formed in BCD code?

BCD (6-bits)
6
It uses 6-bits to code a Character (2 for zone bit and 4 for digit bit) it can represent 2 =
64 characters (10 digits, 26 capital characters and some other special characters).

Some Coding Examples


Character zone zone(2 Bit) digit (4 Bit)
0-9 0 0-9
A-I 3 1-9
J-R 2 1-9
S-Z 1 2-9
A 11 0001
Q 10 1000
8 00 1000
9 00 1001
ASCII-7

ASCII stands for American Standard Code for Information Interchange.


Used widely before the introduction of ASCII-8 (the Extended ASCII)
Uses 7 bits to represent a character;
7
With the seven bits, 2 (or 128) different characters can be coded (0000000-1111111)
Coding examples:
Characterzone (3 bit) digit (4 bit)
0-9 3 0-9
A-O 4 1-15
P-Z 5 0-10

Introduction to ICT Page 11


a- o 6 1-15
p- z 7 0-10
$ 010 0100
% 010 0101
A 100 0001
a 110 0001
b 110 0010

The ASCII System


Also referred as ASCII-8 or Extended ASCII
It is the most widely used type of coding scheme for Micro Computer system
ASCII uses 8-bits to represent alphanumeric characters (letters, digits and special
symbols).
8
With the 8-bits, ASCII can represent 2 or 256 different characters (00000000-11111111)
Coding Examples
Character zone (4 bits) digit (4 bits)
0-9 3 0-9
A-O 4 1-15
P-Z 5 0-10
a-o 6 1-15
p-z 7 0-10
a 0110 0001
b 0110 0010
A 0100 0001
B 0100 0010
? 0011 1111
+ 0010 1011
1 0011 0001

UNITS OF DATA REPRESENTATION


When data is stored, processed or communicated within the computer system, it is
packed in units, arranged from the smallest to the largest; the units are called bit, byte
and word. These units are based on the binary number system.

BIT

􀂙Bits are the smallest units and can convey only two possible states 0 or 1;
􀂙Bit stands for binary digits;
􀂙A bit is a single element in the computer, on a disk that stands for either “ON”
indicating 1 or “OFF” indicating 0;

In the computer “ON” is represented by the existence of current and “OFF” is


represented by the non-existence of current

Introduction to ICT Page 12


On a magnetic disk, the same information is stored by changing the polarity or
magnetized particles on the disk’s surface;

BYTE

Bits can be organized into large units to make them represent more and meaningful
information;
This large unit is called a byte and is the basic “unit of data representation” in a computer
system;
The commonly used byte contains 8 bits.
Since each bit has two states and there are 8 bits in a byte, the total amount of data that
8
can be represented is 2 or 256 possible combinations;
Each byte can represent a character (a character is either a letter, a number or a special
symbol such as +,-,?,*, $, etc
A byte is then used as a unit of measurement in the computer memory, processing unit,
external storage and during communication;
If the computer memory is 524288 byte, this is expressed in short by saying 512KB,
where KB stands for kilobyte.

1 Byte is 8 bits
10
1 Kilobyte (1KB) is 2 or 1024 bytes
20 10
1 Megabyte (MB) is 2 bytes or 2 kilobytes
30 20 10
1 Gigabyte (GB) is 2 bytes or 2 kilobytes or 2 megabytes

WORD

Word refers the number of bits that a computer process at a time or a transmission media
transmits at a time.

Introduction to ICT Page 13


Although bytes can store or transmit information, the process can even be faster if more than one
byte is processed at a once;
A combination of bytes, then form a “word”
A word can contain one, two, three or four bytes based on the capacity of the computer;
Word length is usually given in bits
We say that a computer is 8-bits, a 16 bit, a 32 bit or a 64 bit computer to indicate that the
amount of data it can process at a time.
The large the word length a computer has the more powerful and faster it is.

You might also like