CHAPTER 3 Data Representation and Computer Arithmetic
CHAPTER 3 Data Representation and Computer Arithmetic
The smallest quantity of information that can be stored and manipulated by a computer
is the bit. Bit stands for binary digit meaning a 0 or 1. A group of bits that is stored or
retrieved from the computer memory is called a word which is the basic unit of
information. Words are usually partitioned into a group of eight bits called bytes. The
number of bits in a word is the length of the word. Typical word lengths are 8, 16, and
32 bits.
There are several codes for converting character data into binary strings of which ASCII
(American Standard Code for Information Interchange) and EBCDIC (Extended Binary
Coded Decimal Interchange Code), pronounced “Eb-see-Dick”, are the most popular
codes.
In the ASCII code, a character is represented by 7 bits. A seven bit ASCII code allows a
maximum of 27= 128 different characters, 96 printable and 32 non printable characters.
There is a variant of ASCII known as ASCII-8 which is an 8 bit code.
The EBCDIC code is an 8- bit code. It allows a maximum of 28= 256 characters. ASCII
is used in almost all computer systems except for some IBM mid-range and mainframe
systems that use EBCDIC.
1
Compiled by.Molalign(course Instructor) Department of Computer Science
4.1.2 Binary Code
The word binary is used to refer to two distinct states- on or off, yes or no, 1 or 0
etc.
Computers only understand data converted into the simplest form that can be
processed magnetically or electronically- that is binary form.
To store and process data in a binary form, a way of representing characters,
numbers and other symbols has to be developed.
In other words, coding schemes had to be devised as standard methods for
encoding data for use in computer storage & processing.
In positional number system, there are only few symbols called digits, and these
symbols represent different values depending on the position they occupy in the
number. In computer science, four bases are important or of interest; 2,8,10 and 16 and
are called binary, octal, decimal and hexadecimal respectively.
The number system that we use in our day-to-day life is called the decimal number
system. Here the base is equal to 10, since it uses 10 digits (0,1,2,3,4,5,6,7,8,9).
The general form of decimal number system and its interpretation are as follows.
Place value 10n, 102, 101, 100 10-1, 10-2, 10-m
The binary number system is exactly the same like the decimal number system, except
that the base is two instead of ten. It uses only two digits 0 and 1. Each position in a
binary number system represents a power of the base two. Thus, the decimal
equivalent of the binary number 11001 written as (110012) is
2
Compiled by.Molalign(course Instructor) Department of Computer Science
(1*20)+(0*21)+(0*22)+(1+23)+(1*24)
1 + 0 + 0 + 8 + 16 = 25
(1X20)+(0X21)+(0X22)+(1X23)+(1X24) =
1+0+0+8+16 = 2510
1011102= (1x25)+(0x24)+(1x23)+(1x22)+(1x21)+(0x20) =
32+0+8+4+2+0 = 4610
A binary number consisting of „n‟ bits is called n-bit number, and create 2n different
patterns. If we use 3 bits in our binary number 2 3 =8 different symbols can be simply
created. 4 bits =24=16 different symbols can be created.
- In octal number system the base is 8. So here, we use eight symbols or digits:
0,1,2,3,4,5,6, and 7.
- Each position in an octal number represents a power of the base 8. Thus, the
decimal equivalent of the octal number 2046 = (20468) is
(2x83)+ (0x82) + (4x81) + (6x80)=
3
Compiled by.Molalign(course Instructor) Department of Computer Science
1024+0+32+6 = 1062
Hence, 20468=106210
Since there are only 8 digits in the octal number system, 3 bits (23=8) are
sufficient to represent any octal number in binary.
The hexadecimal number system is a base 16 number system. Here we use 16 digits,
the first 10 digits of the decimal number system 0,1,2,3,4,5,6,7,8,9 and the remaining
six digits are denoted by English symbols, A=10, B=11, C=12, D=13, E=14, F=15.
Thus the decimal equivalent of the hexadecimal number
1AF (1AF16) is:
(1x162)+(Ax161)+(Fx160)
(1x256)+(10x16)+(15x1) = 256 + 160+15 = 43110 , 1AF16 = 43110
4.3 Converting from one number system to another
We are very convenient with decimal numbers since we are using them starting our
elementary education. But it is also easy to convert numbers between different bases.
Converting to decimal from other base
Example 1
110112 =? 10
Solution
1. we have five columns raised to two i.e.
20 = 1, 21= 2, 22= 4, 23= 8, and 24 = 16,
2. Multiply digits
1x1 =1, 2x1=2, 4x0=0, 8x1=8, 16x1=16
3. Sum the product= 1+2+0+8+16= 2710
Example 2
20768 = ?10
Solution
1. 80= 1, 81=8, 82=64, 83= 512
2. 6x1 = 6, 7x8=56, 0x64=0, 2x512=1024
3. 6+56+0+1024= 108610
Example 3
1AC16 =?10
4
Compiled by.Molalign(course Instructor) Department of Computer Science
Solution
1. 160 = 1, 161=16 = 162=256
2. Cx1=C =12, Ax16= 160, 1x256= 256
3. 12+160+256= 42810
Example 1
2510 =?2
Solution Quotient Remainder
252 = 12 and reminder =1
122 = 6 and reminder =0
62 = 3 and reminder =0
32 = 1 and reminder =1
12 = 0 and reminder =1
Example 2
3810 =?2
Quotient Remainder
2 38 = 19 0
19 = 9 1
9 =4 1
4 =2 0
2 =1 0
1 =0 1
3810 = 1001102
5
Compiled by.Molalign(course Instructor) Department of Computer Science
2. Repeat step 1 until a fractional part is identically zero, or until as many digits
as desired have been generated.
3. Record the integral part.
Example 1
68.65 10 = ?2
Quotient Remainder
68/2 34 1
34/2 17 0
17/2 8 1
8/2 4 0 6810 = (1000101)2
4/2 2 0
2/2 1 0
1/2 0 1
.62510 = ?2
.625x2 .250 1
.250x2 .500 0
.500x2 .000 1
.62510 = (.101)2
Example 2
95210 = ?8
reminder
8 952 = 119 0
119 =14 7
14 = 1 6
1 =0 1
Shortcut Methods
1. Divide the binary digits into groups of three (staring from the right)
2. Convert each group into one octal digit and combine all.
Example 1
1011102 = ?8
101 and 110
101= (1x20) + (0x21) + (1x22)
1 + 0 + 4 = 58
110= (0x20) + (1x21) + (1x22)
0 + 2 + 4 = 68
(1011102) = 568
Example 2
101011.010 1102 = ?8
101 011. 010 110
5 3 2 6
(101011.010110)2 = (53.26)8
Example 3
11010102 = ?8
001 101 010
001 = (1x20) + (0x21) + (0x22)
7
Compiled by.Molalign(course Instructor) Department of Computer Science
1 + 0 + 0 = 18
101 = (1x20) + (0x21) + (1x22)
1 + 0 + 4 = 58
010 = (0x20) + (1x21) + (0x22)
0 + 2 + 0 = 28
= 152
(11010102) = 1528
Octal to Binary
Convert each octal digit into three binary digits
Example 1
5628 = ?2
5 = 101, 6 = 110, 2 = 010
5628 = (1011100102
Example 2
42678 = ?2
4 = 100, 2 = 010, 6 = 110, 7 = 111
42678 = (1000101101112)
Binary to Hexadecimal
Example 1
110100112 = ?16
Divide into two groups in group of 4 digits, starting from right.
1101 0011
1101 = 13 = D
0011 = 3
= D3
110100112 = D316
Example 2
101101011002 = ?16
0101 1010 1100
5 10 12
5 A C
101101011002 = 5AC16
8
Compiled by.Molalign(course Instructor) Department of Computer Science
Hexadecimal to Binary
Example 1
2AB16 = ?2
Convert each hexadecimal digit to 4 binary digits
2 = 0010 A = 1010 B = 1011
Example 2
ABC16 = ?2
A = 1010, B= 1011, C= 1100
ABC16 =(1010101111002)
Example 1
10.012 = (1x21)+ (0x20)+ (0x2-1)+ (1x2-2)
2+0+ 0 1
2 4
1
2+ = 9
4 4
= 2.25
10.012 = 2.2510
Example 2
110.1012 =?10
(1x22) + (1x21) + (0x20)+ (1x2-1) + (0x2-2)+ (1x2-3)
4+2+0+ 1 +0+ 1
2 8
= 4+ 2 + 0.5 + 0.125
= 6 + 0.5 + 0.125
= 6.625
110.1012 = 6.62510
9
Compiled by.Molalign(course Instructor) Department of Computer Science
Example 3
127.548 = ?10
(1x82) + (2x81) + (7x80)+ (5x8-1) + (4x8-2)
= 64 + 16 + 7 + 5 4
8 64
= 87 + 0 .625+0.0625
= 87.687510
127.548 =87.687510
Example 4
2B.C416 = ?10
(2x161) + (Bx160) + (Cx16-1)+ (4x16-2)
= 32 + 11 + 12 + 4
16 256
= 43 + 0.75 + 0.015625
= 43.76565210
2B.C416 =43.76565210
Addition in binary is precisely similar to addition in decimal. Working from the left, if the
sum of two digits produces a two digit result, the digit on the right is written down and
the digit on the left is added to the next column to the left.
As a general rule, look the following
0+0=0
0 + 1= 1
1+ 0 = 1
1+ 1= 0, Plus a carry of 1 to the next higher column.
Example 1
a) 101 = 5 b) 10011 = 19 c) =39
+10 +2 +1001 +9 100111 +27
1112 710 11100 28 +11011 66
1000010
d) 111110 = 62 e) 10011 19
+100111 9 00111 7
1100101 101 + 11111 + 31
10
Compiled by.Molalign(course Instructor) Department of Computer Science
00111 7
01001 9
1001001 73
f) 110.1101
+010.0111
111.0011
10000.0111
You can recall that in decimal subtraction one subtracts a decimal digit from a smaller
digit by borrowing 1 from the term on the left. Binary subtraction can be accomplished
similarly. The borrowed 1 and the 0 of the location involved combine to form (10) 2.
Thus, if there is a digit on the left, 0 – 1 becomes 10 – 1 = 1, with one borrowed from the
left.
0-0=0
1–0=1
1–1=0
0 – 1 = 1, with a borrow from the next column
Example 2
a) 10101 = 21 b) 1011100 = 92 c) 10001 17
-0111014 -0111000 -56 - 10 -2
00111 710 01001003610 1111 15
11
Compiled by.Molalign(course Instructor) Department of Computer Science
Example 3
a) 1010 = 10 b) 1111
x1001 x 9 x111
1010 90 1111
0000 1111
0000 1111
1010
1011010 1101001
Binary division is similar in procedure to decimal division. The placement of the binary
point is exactly the same as the placement of the decimal point in decimal division.
01=0
11=1
Example 4
11
10 110
10 111
a) 10 c) 110 101010
10 110
1001
110
110
110
000
b) 1000012 1102
0101
110 100001
110 Divisor > 100, so put 0 in quotient
1000
101
001001
110
11
12
Compiled by.Molalign(course Instructor) Department of Computer Science