You are on page 1of 16

CHAPTER 1 Data Representation in Computers

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. So data are
represented in the form of a code which can have a corresponding electrical signal. Internal
arithmetic operations of a computer are actually performed in binary number system. Thus, an
understanding of the binary number system is essential.

2.1 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.
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
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
(1*20)+(0*21)+(0*22)+(1+23)+(1*24)

1|Page
1 + 0 + 0 + 8 + 16 = 25
(1X20)+(0X21)+(0X22)+(1X23)+(1X24) =
1+0+0+8+16 = 2510
1011102= (1x2 )+(0x24)+(1x23)+(1x22)+(1x21)+(0x20) =
5

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 23 =8 different symbols can be simply created. 4 bits =24 =16
different symbols can be created.
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)=
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.
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

2.2 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|Page
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
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

3|Page
25/2 = 12 and reminder =1
12/2 = 6 and reminder =0
6/2 = 3 and reminder =0

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

.30x2 .60 0
.60x2 .20 1

5 35
| P| aPga eg e
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

.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

6|Page
119 =14 7
14 = 1 6
1 =0 1

Hence, 95210 = 16708


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

7|Page
Example 3
11010102 = ?8
001 101 010
001 = (1x20) + (0x21) + (0x22)
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

8|Page
110100112 = D316

Example 2
101101011002 = ?16
0101 1010 1100
5 10 12
5 A C
101101011002 = 5AC16

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)

5 3
60 + 8 + +
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)

9|Page
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
Example 3
127.548 = ?10
(1x82) + (2x81) + (7x80) + (5x8-1) + (4x8-2)

5
= 64 + 16 + 7 + 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)
12 4
= 32 + 11 + +
16 256
= 43 + 0.75 + 0.015625
= 43.76565210
2B.C416 = 43.76565210
10 | P a g e
3.3 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.
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.
1 +1 +1= 1, plus a carry of 1 to the nest higher column.
Example 1
a) 101 =5 b) 10011 = 19 c) 100111 =39
+10 +2 +1001 +9 +11011
+27
1112 710 11100 28 1000010 66

2.4 Units of Data Representation


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

11 | P a g e
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).
 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 nonexistence of current
 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 can be represented is 28 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 Kilobyte(1KB) is 210 or 1024 bytes
 1 Megabyte(MB) is 220 bytes or 210 kilobytes

12 | P a g e
 1 Gigabyte(GB) is 230 bytes or 220 kilobytes or 210 megabytes
Words
 Word refers the number of bits that a computer process at a time or a transmission
media transmits at a time
 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 an 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.

3.5 Coding Methods


As computers have evolved, character codes have evolved. Larger computer memories
and storage devices permit richer character codes. 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.
BCD (6-bits)
• Stands for Binary Coded Decimal
• It uses 6-bits to code a Character
• The earliest computer coding systems used six bits.
• Binary-coded decimal (BCD) was one of these early codes. It was used by IBM
mainframes in the 1950s and 1960s.
Coding Examples:
Character Zone digits
A 11 0001
Q 10 1000
8 00 1000
9 00 1001
EBCDIC

13 | P a g e
EBCDIC pronounced as “Eb-see-dick” and stands for Extended Binary Coded Decimal
Interchange Code. In 1964, BCD was extended to an 8-bit code, Extended Binary-Coded
Decimal Interchange Code (EBCDIC). EBCDIC was one of the first widely-used
computer codes that supported upper and lowercase alphabetic characters, in addition to
special characters, such as punctuation and control characters. EBCDIC and BCD are
still in use by IBM mainframes today.
It is an 8-bit coding scheme; (00000000 – 11111111)

• It accommodates to code 28 or 256 different characters It is a standard coding


scheme for the large computers.
Coding Examples:
Character Zone Digit
a 1000 0001
b 1000 0010
A 1100 0001
B 1100 0010
0 1111 0000
ASCII-7
ASCII stands for American Standard Code for Information Interchange. Other computer
manufacturers chose the 7-bit ASCII (American Standard Code for Information
Interchange) as a replacement for 6-bit codes. While BCD and EBCDIC were based
upon punched card codes, ASCII was based upon telecommunications (Telex) codes.
Until recently, ASCII was the dominant character code outside the IBM mainframe
world. Used widely before the introduction of ASCII-
8 (the Extended ASCII)
• Uses 7 bits to represent a character;
• With the seven bits, 27( or 128) different characters can be coded (0000000-1111111)
It has a zone and digit bits positions Coding examples:
Character Zone digit
$ 010 0100
A 100 0001
a 110 0001
The ASCII System
• Also referred as ASCII-8 or Extended ASCII
14 | P a g e
• 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).
• With the 8-bits, ASCII can represent 28 or 256 different characters (00000000-
11111111).
Coding Examples
Character Binary representation in ASCII
a 01100001 b
01100010 A
01000001
B 01000010
? 00111111
1 00110001
Unicode Representation
ASCII code can represent only 128 = 27 characters. It only represents the English
Alphabet plus some control characters. Unicode is designed to represent the worldwide
interchange. Many of today’s systems embrace Unicode, a 16-bit system that can encode
the characters of every language in the world. It uses 16 bits and can represent 32,768
characters. For compatibility, the first 128 Unicode are the same as the one of the ASCII.
The Java programming language and some operating systems now use Unicode as their
default character code. The Unicode code space is divided into six parts. The first part is
for Western alphabet codes, including English, Greek, and Russian.

15 | P a g e
Colour Representation
 Colours can be represented using a sequence of bits.
 256 colours – how many bits?
• To figure out how many bits are needed to represent a range of values,
figure out the smallest power of 2 that is equal to or bigger than the size
of the range.
• That is, find x for 2 x => 256
 24-bit colour – how many possible colors can be represented?
• 16 million possible colours

*********

16 | P a g e

You might also like