Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

CHAPTER THREE

Data Representation and Computer Arithmetic

4.1 Data Representation in Computers

Internal arithmetic operations of a computer are actually performed in binary number


system. Thus, an understanding of the binary number system is essential.

4.1.1 Bits, Bytes and Words

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.

A word in a memory of a computer can represent character data or numerical data.


Characters may be classified as letters and/or digits (A to Z, or a to z,
or 0 to 9 ), special symbols such as ?, *, &, + , _, and control characters which are used
to control devices. When characters are used in the computer, they must be converted
into a binary string (i.e. sequence of 0‟s and 1‟s).

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.

 A scheme for encoding data using a series of binary digits is called a


binary code.
 The binary digit (bit) is either the character 1 (on) or 0 (off).

4.2 Number Systems in Computers

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.

4.2.1 Decimal Number System

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 general form for decimal 4206 is:


(4*103)+ (2*102) + (0*101) + (6*100)
4000 + 200 + 0 + 6 = 4206

The general form for 253.252 is


(2*102)+(5*101)+(3*100)+(2*10-1)+(5*10-2)+(2*10-3)
200 + 50 + 3 + 2/10 + 5/100 + 2/1000 = 253.252

4.2.2 Binary Number System

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.

2 bits 3 bit binary 4 bit binary decimal equivalent


00 000 0000 0
01 001 0001 1
10 010 0010 2
11 011 0011 3
100 0100 4
101 0101 5
110 0110 6
111 0111 7
1000 8
1001 9
1010 10
1011 11
1100 12
1101 13
1110 14
1111 15
0000
0
Figure 4.2 Decimal number representation using two bit, three bit, and four bit binary digits.

4.2.3 Octal Number System

- 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.

4.2.4 Hexadecimal Number System

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

Follow the following three steps:


1. Determine the column value of each digit
2. Multiply the obtained value by the digit in the corresponding columns.
3. Sum the products calculated in step two.

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

Converting from decimal integer to another base (Division-remainder technique)


Follow the following four steps:
1. Divide the decimal number by the value of the new base.
2. Record the remainder from step1.
3. Divide the quotient by the base until a zero quotient is obtained.
4. Record the remainder in the reverse order.

Example 1
2510 =?2
Solution Quotient Remainder
252 = 12 and reminder =1
122 = 6 and reminder =0
62 = 3 and reminder =0
32 = 1 and reminder =1
12 = 0 and reminder =1

Hence 2510= 110012

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

Converting a decimal fraction to a fraction of another base

1. Multiply the given decimal fraction by the base.

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

Fractional Part Integral Part


.65x2 .30 1
.30x2 .60 0
.60x2 .20 1
.20x2 .40 0 .6510 = (.1010011)2
.40x2 .80 0
.80x2 .60 1
.60x2 .20 1

Thus 68.65 = (1000101.1010011..)2

.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

Hence, 95210 = 16708


6
Compiled by.Molalign(course Instructor) Department of Computer Science
Example 3
42810 = ?16
reminder
16 428 26 C = 12
26 1 A = 10
1 0 1= 1
42810 = 1AC16

Shortcut Methods

From Binary to Octal

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

2AB16 = (0010101010112) = 10101010112

Example 2
ABC16 = ?2
A = 1010, B= 1011, C= 1100

ABC16 =(1010101111002)

Fractional Numbers in Binary Number System

68.53 = (6x101)+ (8x100)+ (5x10-1)+ (3x10-2)


60 + 8 + 5 + 3
10 100
= 6853 = 68.53
100
For binary number system we use the same principle.

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

4.4 Binary Arithmetic

Internal arithmetic operations of a computer are actually performed in binary number


system. It will be valuable for the reader to study the basic arithmetic of the binary
numbers so as to acquire a fundamental understanding of the internal structure of a
computer.

4.4.1 Binary Addition

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

 Add the l s‟ in the right most column = 5. Then divide 5 by 2= 5/2 = 2 as a


quotient and 1 as a remainder.
Write the remainder and carry the quotient to the left column
5/2 =2 1
6/2 = 3 0
6/2 = 3 0
5/2 = 2 1
 Finally write down the binary equivalent of 4 = 100

f) 110.1101
+010.0111
111.0011
10000.0111

4.4.2 Binary Subtraction

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

4.4.3 Binary Multiplication

Binary multiplication is identical to decimal multiplication.


0x0=0
0x1=0
1x0=0
1x1=1

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

4.4.4 Binary Division

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.

01=0
11=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

You might also like