Introduction to computer and its application Chapter Four
Chapter Four
Data Representation in Computers
4.1 Introduction
Data representation is how the numbers represented to calculate, edit, save and use.
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.
Every computers store numbers, letters, and other special characters in coded form.
4.2 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
On a magnetic disk, the same information is stored by changing the polarity or magnetized particles on the disk’s surface;
Compiled by Fikreab L. for DoH summer students Page 1
Introduction to computer and its application Chapter Four
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
1 Gigabyte(GB) is 230 bytes or 220 kilobytes or 210 megabytes
WORD
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.
4.3 Number Systems
A number system is a set of symbols used for counting
There are various number systems
E.g. Decimal, Binary, Octal-decimal, Hexadecimal, etc.
Number system is basically of two types: Non-positional and positional.
1. Non-positional number – such as I, II, III, IV, V…. Each symbol represents the same value, regardless of its position in the number, and
symbols are simply added to find out the value of particular number.
Compiled by Fikreab L. for DoH summer students Page 2
Introduction to computer and its application Chapter Four
2. Positional Numbers: There are only few symbols called digits. The value of each digit in such number is determined by three considerations:
The digit itself
The position of the digit in the number
The base of the number system (where base is defined as the total number of digits available in the number system.)
Example:
2586 = (2X1000) + (5X100) + (8X10) + (6X1)
In 258610 the digit 6 signifies 6 X 100 = 6
In 258610 the digit 8 signifies 8 X 101 = 80
In 258610 the digit 5 signifies 5 X102 = 500
In 258610 the digit 2 signifies 2 X 103 = 2000
Different Number Systems
1. Decimal Number System – with the base of 10 and symbol used are 0,1, 2……..9
2. Binary Number System – with the base of 2 and symbol used are 1 & 0.
3. Octal Number System – with the base of 8 and symbol used are 0,1,… 7
4. Hexadecimal Number System – with the base of 16 and symbol used are 0, 1,….9, A, B,… F representing the decimal values 10, 11... 15.
Conversion of Number Systems
The values that members have within given number systems are largely determined by their positional notation. Positional notation means that the
position of one symbol relative to other symbols in a given number system determines the value of that symbol. For example, these 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:
(135) 10 = 1*102+3*101+5*100
The subscript 10 is used to indicate that 135 is a base 10 number.
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.
Compiled by Fikreab L. for DoH summer students Page 3
Introduction to computer and its application Chapter Four
The binary number 1101 may be expanded as
11012 = 1*23+1*22+0*21+1*20
= (1*8)+(1*4)+(0*2)+(1*1)
= 8+4+0+1
= 1310
Conversion from decimal (base 10) to other base (base B)
To convert an integer to Base B (Base 10……….Base M) there are some steps we should have to follow.
To convert a decimal number X to a number in base B,
Steps:
1. Divide X by B, find the remainder,
2. Again divide the result (quotient) by B, find the remainder, and continue until the result (quotient) is 0.
3. Concatenate (collect) the remainders starting from the last up to the first.
A. Decimal to Binary:
2
2 47 0
235
470610 = _________________ 2 2
211
506 1
0
2
232 0
76
1 0
Answer: 10010011000102
2
2897
3 1
1
More examples: 2
284
13
9 0
0
▪ 169410 = ?2
2 46 1
72 0
▪ 13510 = ?2
28
2 1 0
0 1
B. Decimal to Octal number
Example: 250210 = ________ 8 82
3
85 6
Answer: 47068
81
3 0
80
4 7
9
0
2 4
Compiled by Fikreab L.
2 for DoH summer students Page 4
Introduction to computer and its application Chapter Four
More Examples:
▪ 56210 = ?8
▪ 261410 = ?8
C. Decimal to Hexadecimal
14
Example: 42810 = _______ 16
Answer: 1AC 1 21
16
1
60 211
More samples:
6 621
2573 = ?10 16 68 0
4563 =? =
=
10 16
Conversion from base B to base 10 (decimal) C
A
To convert a number X consists of digits X1 X2 X3 … Xn in base b to decimal; simply
expand the number with base b. That is
(X1X2X3…Xn)b =X1*bn-1+X2*bn-2 +X3*bn-3+ …. + XI*bn-i+… Xn- b1+Xn*b0
1
=Y10
D. Binary to Decimal:
Example:
110012 = _______ 10
Answer: 2510
More Examples:
• 1111012 = ?10
• 101010102 = ?10
Compiled by Fikreab L. for DoH summer students Page 5
Introduction to computer and its application Chapter Four
E. Octal to Decimal
Example:
5628 = ________ 10
Answer: 37010
More samples:
• 7628 = ?10
• 51278 = ?10
F. Hexadecimal to Decimal
Example:
2A3B16 = _________ 10
Answer: 1081110
More samples:
• A2BD416 =?10
• CFFE216 = ?10
Octal Binary
Other Conversions
0 000
a. Binary to Octal
1 001
Steps to be followed in order to convert binary numbers into octal (base 8) are:
Steps: 2 010
1. Group three binary digits (triplets) together starting from the last digit (right side)
3 011
2. If there are no enough digits add zeros in the left side of the numbers
3. Find the corresponding Octal of each group. 4 100
Compiled by Fikreab L. for DoH5summer students
101 Page 6
6 110
7 111
Introduction to computer and its application Chapter Four
Example:
1011102 = _____ 8
Answer:101110
5 6
568
b. Octal to Binary
Convert each octal digit to its equivalent
3 bit (triplets) binary starting from right.
Example1:
5628 = _____ 2
Answer: 5 6 2
101 110 010
101 110 0102
Example 2:
Convert (675)8 to binary
Convert 2318 to binary
c. Binary to Hexadecimal
To convert binary to hexadecimal steps we should have to follow are:
Steps:
1. Group digits into quadruplets (four) binary digits together starting from right and
2. If there are no enough digits add zeros at the left side of the numbers.
3. Find their hexadecimal equivalence for each group
Example: 110100112 = _______ 16
Compiled by Fikreab L.
1101
D for DoH summer students Page 7
0011
Introduction to computer and its application Chapter Four
Answer:11010011
D 3
D316
Example: 1110001102 = ______ 16
Answer: 1C616
d. Hexadecimal to Binary
Convert each octal digit to its equivalent 4 bit (quadruplets) binary starting from right.
Example: 2AB16 = _______ 2
Answer:2AB
001010101011
216 =
0010101010112
00102
e. Octal To Hexadecimal
A16 =
Steps: 10102
1. Convert the Octal digit to Binary
B16
2. Convert the Binary digit to Hexadecimal digit.=
Example1. Convert 235 to hexadecimal 1011
8
2
2388=010 011 101
=0000 1001 1101
= 0 9 13
=9D16
Compiled by Fikreab L. for DoH summer students Page 8
Introduction to computer and its application Chapter Four
f. Hexadecimal to Octal
Steps:
1. Convert the Hexadecimal digit to Binary
2. Convert the Binary digit to Octal digit.
Example1. Convert 1A to Octal
1A=0001 1010
=000 011 010
=0 3 2
=328
Summary of conversion from One base to another base
Fig 3.3.1 Summary of Conversion from One base to another base
Compiled by Fikreab L. for DoH summer students Page 9
Introduction to computer and its application Chapter Four
Fractional Numbers
It is generally same way in the decimal number.
0.235 = (2X10-1) + (3X10-2 )+ (5X10-3)
68.53 = (6X101) + (8X100) + (5X10-1) + (3X10-2)
Position 4 3 2 1 0
-1. -2 -3 -4
Position Value 24 23 22
21 20. 2-1 2-2 2-3 2-4
Quantity
Represented 16 8 4 2
1 . ½ ¼ 1/8 1/16
Example:
Find the decimal equivalent of the binary number 110.1012.
Solution:
110.1012 = 1 x 22 + 1 x Another example:
Find the decimal equivalent of the hexadecimal number 2B.C4 .
16
2 +0x2 +1x2 +0x
1 0 -1 Solution:
Another example:
2 +1
-2
2B.C4 x2 -3
16 = 2x16 + Bx16
1 0 Find the decimal equivalent of the octal number 127.54 .
8
Solution:
+ cx16 + 4x16 =
-1 4 + 2 -2+ 0 + 0.5
+ 0by Fikreab
Compiled +=0.125L.
32 + 11for DoH summer students Page 10
+ 12/16 = + 6 +4/256
0.5 + 0.125
Introduction to computer and its application Chapter Four
Converting fractional numbers to binary
0.256 x 2
Example:
Answer:
0.25610 = ______ 2
0.0100000112
= 0.512
0
0.512 x 2
4.4 BINARY ARITHMETIC = 1.024
A. Binary Addition 1
Is performed in the same manner as in decimal arithmetic.
0.024
Since 1 is the largest digit in the binary number system, any sum greater thanx 2 a digit to be carried over.
1 requires
Use the following general formal for adding binary numbers
= 0.048
0 +0 0
0 1
0+1
10.048
+0 1 x2
1=+ 1 0.096
0 plus a
carry of 1
Example: 0
1.) 101 + 10
B D 0.096 x 2
2 2
i ec = 0.192
for DoH0
Compiled by Fikreab L.
1
n im
a al
summer students
0.192 x 2
Page 11
5
Introduction to computer and its application Chapter Four
2.) 100112 + 10012
carry
-1 1
1
B. Binary Subtraction – is applied to subtraction of numbers in other number systems.
a. Determine if it is necessary to borrow.
b. If the subtrahend (the lower digit) is larger than the minuend (the upper digit), it is necessary to borrow
from the column to the left.
c. It is important to note here that the value borrowed depends upon the base of the number system.
1
d. Simply to subtract lower value from the upper value.
0–0 0
10
1–0 1
9
1–1
0–1
0
01
1 with a borrow +
1
from the next
column
Example:
Subtract 011102 from 101012 12
Answer - 001112
+ 9
100202
2
Additive Method of subtraction – is known as complementary subtraction.
Complement subtractions: 011010
8
Compiled by Fikreab L.
1 for DoH summer students Page 12
-
0111
Introduction to computer and its application Chapter Four
For a number which has n digits in it, a complementary is defined as the difference between the numbers and the based raised to the
nthpower minus one.
(Base) n - 1
Example:
Find the complement of 3710.
Solution:
Since the number has 2
digits, and the value of base is
10.
(Base)n – 1 = 102 – 1 = 99
Now, 99 – 37 = 62
Hence, the complement of
3710 = 6210
Another example:
Find the complement of 101012.
Compiled by Fikreab L. for DoH summer students Page 13
Introduction to computer and its application Chapter Four
Solution:
Since the number has 5 digits,
and the value of base is 2.
(Base)n – 1 = 25 – 1 = 3110
Also, 101012 = 2110
Now, 3110 – 2110 = 1010 - 10102
Hence, the complement of
101012 = 010102
Subtraction by the complementary
Themethod involves the following steps:
Find the complement of the number you are subtracting (subtrahend)
Add this to the number from which you are taking away (minuend)
If there is a carry 1, add it to obtain the result; if there is no carry, recomplement the sum and attach a negative sign to obtain the result.
Example:
Subtract 5610 from 9210 using complementary method.
Compiled by Fikreab L. for DoH summer students Page 14
Introduction to computer and its application Chapter Four
C. Binary Multiplication – also follows the same general rules as multiplication in decimal number system.
0X0 0
0X1 0
1X0 0
1X1 1
Example:
Multiply the binary numbers 1010 and 1001
Solution:
Multiplica
1010 Partialnd
X Multiplier
product
1001 Partial
Final product
product
1010
D. Binary Division – it is
1 Start from the left ofPartial
similar to decimal division. The rules for binary division are:
the dividend
2 Perform a series of
3 If subtraction
product
is
subtractions, in which the divisor is subtracted from the dividend.
possible, put a 1 in the quotient and subtract the divisor form the
0000
corresponding digitsPartial of dividend.
5 Bring down the nextproduct
4 If subtraction is not possible (divisor greater than remainder), record a 0 in the quotient.
digit to add to the remainder digits. Proceed as before in a manner similar to
0000
long division.
1010
1011
010
Compiled by Fikreab L. for DoH summer students Page 15
Introduction to computer and its application Chapter Four
Example:
Divide binary 100001 by 110.
010 Quotient
1 10 Dividend
1 1 Divisor greater than 100, hence, put 0
11
1 00 2 Add in quotient
digit from dividend to group used
1
0 00 above
Subtract possible, hence, put 1 in
0 01
11
010 3 Divisor
quotient
Remainder from subtraction plus digit from
011 4 quotient
dividendgreater, hence, put 0 in
0
10
Add digit from dividend to group used
011 5 above Subtract possible, hence, put 1 in
01 6 quotient
011r
remainde
7
4.5 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 an equivalent arrangements of bits
There are different coding systems that convert one or more character sets into computer codes. Some are: EBCDIC, BCD, ASCII-7 & ASCII-8
In all cases, binary coding schemes separate the characters, known as character set, in to zones.
A zone groups characters together so as to make the data easier to process by computers. Within each zone the individual characters are
identified by digit code.
1. BCDcode
o Stands for Binary Coded Decimal
o It uses 6-bits to code a Character
Compiled by Fikreab L. for DoH summer students Page 16
Introduction to computer and its application Chapter Four
Coding Examples
Character 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
BCD
Character Zone digits
A 11 0001
Q 10 1000
8 00 1000
9 00 1001
2. EBCDIC code
o The BCD code was extended from 6-bit to 8-bit code.
o The added 2 bits are used as additional zone bits, expanding the zone to 4 bits.
o The resulting code is called EBCDIC.
o It is possible to represent 256 (28) different characters, instead of 64 (26).
o It is a standard coding scheme for the large computers.
Coding Examples
EBCDIC
Character zone (4BIT) 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 1-9
Compiled by Fikreab L. for DoH summer students Page 17
Introduction to computer and its application Chapter Four
Coding Examples:
Character Zone Digit
b 1000 0010
A 1100 0001
B 1100 0010
9 1111 1001
Example:
Using Binary notation, write the EBCDIC coding for the word BIT. How many bytes are required for this representation?
Solution:
B = 1100 0010 in
EBCDIC binary
1100001011001001
3 bytes will notation
11100011
be required for this representation, because each letter requires 1
byte (or 8 bits)
3. ASCII-7I = 1100 1001 in
B I
o Used
EBCDIC
o ASCII stands for
widely T binary
American Standard Code for Information Interchange
before the introduction of ASCII-8 (the Extended ASCII)
o Uses 7 notationbits to represent a character;
o With the seven bits, 27( or 128) different characters can be coded (0000000-
1111111) T = 1110 0011 in
EBCDIC binary
Coding examples:
Character notation zone (3 BIT) digit(4 BIT)
0-9 3 0-9
A-O 4 1-15
Compiled by Fikreab L. for DoH summer students Page 18
Introduction to computer and its application Chapter Four
P-Z 5 0-10
ASCII-7
Character Zone digit
$ 010 0100
% 010 0101
A 100 0001
a 110 0001
b 110 0010
Examples
Write the binary coding for the word BOY in ASCII-7. How many bytes are required for this representation?
Solution:
B = 1000010 in ASCII-7 binary notation 10000101001111101
O = 1001111 in ASCII-7 binary notation 1001
Y = 1011001 in ASCII-7 binary notation
B O
Since each character in ASCII-7 requires one byte for its representation, and there are 3
Y
characters in the word BOY, 3 bytes will be required for this representation.
4. The ASCII System
o Also referred as ASCII-8 or Extended ASCII
o It is the most widely used type of coding scheme for Micro Computer system
o ASCII uses 8-bits to represent alphanumeric characters(letters, digits and special symbols).
o With the 8-bits, ASCII can represent 28 or 256 different characters(00000000-11111111).
Coding Examples
Character Representation
0-9 48-57
A-Z 65-90
a-z 97-122
Compiled by Fikreab L. for DoH summer students Page 19
Introduction to computer and its application Chapter Four
ASCII-8
Character Zone digit
A-O 0100 1-15
P-Z 0101 0-10
a-o 0110 1-15
p-z 0111 0-10
0-9 0011 0-9
Special characters 0010 0-15
Coding Examples
a 01100001
b 01100010
A 01000001
B 01000010
? 00111111
+ 00101011
1 00110001
200110010
300110011
Example: Write the binary coding for the word SKY in ASCII-8. How many bytes are required for this representation?
Solution:
S = 01010011 in ASCII-8 binary notation
K = 01001011 in ASCII-8 binary notation
Y = 01011001 in ASCII-8 binary notation
Since each character in ASCII-8 requires one byte for its representation, and there are 3 characters in the word SKY, 3 bytes will be required for
this representation.
Compiled by Fikreab L. for DoH summer students Page 20