CHAPTER 1 Data Representation in Computers
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.
(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)
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
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
Example 2
95210 = ?8
reminder
8 952 = 119 0
6|Page
119 =14 7
14 = 1 6
1 =0 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
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.
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)
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