0% found this document useful (0 votes)
5 views

Data Representation

Chapter Six discusses data representation, focusing on the methods used to represent information in computers, including various number systems such as decimal, binary, octal, and hexadecimal. It covers the conversion processes between these systems and introduces concepts of computer arithmetic, including binary addition, subtraction, and the representation of negative numbers. The chapter aims to provide learners with a comprehensive understanding of how data is represented and manipulated within computer systems.

Uploaded by

muindekelvin609
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Data Representation

Chapter Six discusses data representation, focusing on the methods used to represent information in computers, including various number systems such as decimal, binary, octal, and hexadecimal. It covers the conversion processes between these systems and introduces concepts of computer arithmetic, including binary addition, subtraction, and the representation of negative numbers. The chapter aims to provide learners with a comprehensive understanding of how data is represented and manipulated within computer systems.

Uploaded by

muindekelvin609
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

CHAPTER SIX

DATA REPRESENTATION

Introduction

In the previous topic we learned about Data communication, in that discussion we talked
about the various types of transmission media, and the basic elements of a
communication system. We then finished by talking about networks and classified them
according to their topologies. This topic introduces you to data representation which
refers to the methods used internally to represent information stored in a computer. We
shall also look in depth at the number systems and how one can convert from one number
system to another. The topic has eight sections namely:

• Introduction to data representation


• Number systems e.g. decimal number system, binary
number system octal number system
• Hexadecimal number system
• Conversions of number system
• ASCII, EBCDIC, UNICODE

Objectives

By the end of the topic the learner should be able to:


1) Define data representation
2) Explain the procedures of various number systems
3) Carry out conversions of the various number systems

139
Activity 1
In your own words define data representation

……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

Now try and name some number systems you know about
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………

Topic Overview

If you are able to answer the questions above, then you have some idea on what data
representation is. It is important however to have an in depth knowledge of the number
systems that the computer system uses to store information. In this topic we will explore
these systems to help you understand.

6.1 Introduction
Computers not only process numbers, letters and special symbols but also complex types
of data such as sound and pictures. However, these complex types of data take a lot of
memory and processor time when coded in binary form. This limitation necessitates the
need to develop better ways of handling long streams of binary digits. Higher number
systems are used in computing to reduce these streams of binary to

140
manageable form. This helps to improve the processing speed and optimize memory
usage. Armed with this introduction let us venture into the number systems used by
computers.

6.1.1 Number Systems and their Representation


A number system can be defined as a set of symbols used to represent values derived
from a common base also known as radix. As far as computers are concerned, number
systems can be classified into four major categories;

• Decimal number systems


• Binary number systems
• Octal number systems
• Hexadecimal number systems

Representing numbers

The storage and processing elements of a computer are two-state (or bi stable) electronic
devices. They are used in computers because they are quick and reliable and take up only
small amounts of space and energy. For this reason, the base two or binary number
system which uses the two digits 0 and 1 (for off and on) is suited to computers. The
binary digits are known as BITS.

Let us now consider each number system and its representation

6.1.1.1 Decimal Number System


This is the first number system for us to discuss. The term decimal is derived from a Latin
prefix deci which means ten. The decimal number system has ten digits ranging from 0 –
9. Because this system has ten digits, it’s also called base ten number system or the denary
number system. A decimal number should always be written with a subscript 10 e.g. X10
but since this is the most widely used number system all over the world the subscript is
normally understood and ignored in written work. However, when many number
systems are being considered or in calculations the subscript must always be put so as to
differentiate it from other number systems.

141
The magnitude of a number is evaluated using three parameters

Absolute value
Place value or positional value
Base value

The absolute value is magnitude of a digit. For example, the digit 5 in the number 7458
has an absolute value of 5 according to its value in the number line.
The positional/place value of a digit in a number refers to the position of that digit in
that number, that is whether ‘tens’, ‘hundreds’ or ‘thousands’.

Thousands, 103 Hundreds, 102 Tens, 101 Ones, 100


7 4 5 8

The total value of a number is the sum of the place value of each digit making the
number. For example, the total value of the digits in the table above can be worked as
shown N10 = (7*103) + (4*102) + (5*101) + (8*100)
= (7*1000) + (4*100) + (5*10) + (8*1)
= 7000+400+50+8
= 7458
The base number of a number also known as the radix is the type of number system that
is being used. The value of any number depends on the radix.
As we continue let us deal with more examples for better
understanding We count in base (or radix) 10
Tens Units
7
+ 9
6
This simple example illustrates the most important feature of a number system: that the
value of a figure depends on its position or place. For example, the decimal number 267
really means:
267= (2*102) + (6* 101) + (7*100)

6.1.2 Binary Numbers


After dealing with the decimal number system at least you have gotten a little versed with
the number systems now we can proceed to a different number system known as the
binary number system. In contrast, the binary number system has only two digits, 0 or 1,
and the place values are units, 2’s, 4’s, 8’s, and 16’s and so on. Unlike the decimal numbers
where the place values go up in factors of ten, in the binary system the place values
increase by factors of two. Binary numbers are written as X2.

142
E.g. 01012 = 0 * 23 +1*22+0*21+1*20
= 0+4+0+1
= 510 (subscript denotes base, i.e. 10)
A decimal number may be represented in a computer by using two state devices 9 such
as semiconductors) to represent its binary equivalent. For example, the decimal number
25 could be.
Device
Position 25 24 23 22 21 20
Value (32) (16)(8)(4)(2)(1)
Code device ‘on’ (1bit)
Device’ off’ (0 bit)

6.1.2.1 Conversion from Decimal to Binary


This can be done by successive divisions by 2, recording the reminder of each division.
E.g 6710 67/2=33 remainder 1
33/2=16 remainder 1
16/2=8 remainder 0
8/2=4 reminder 0
4/2=2 remainder 0
2/2=1 remainder 0
½=0 remainder 1
6710

6.1.3 Octal Numbers


The octal number system uses eight digits running from 0 – 7 to represent values of a
number. The place value of octal numbers goes up in factors of eight from right to left.
For example, to represent an octal number such as 72458 we do so by placing each number
in its positional value.

Place values 83 = 512 82=64 81=8 80=1


Octal numbers 7 2 4 5

Conversions to other number systems


Decimal to octal
e.g. 6910 69 /8=8 remainder 5
8/8=1 remainder 0
1/8 remainder 1
6910=1 0 58

143
2. Octal to
Decimal E.g.1148

Place values 82 81 80
(64) (8) (1)
Octal number 1 1 4
conversion (1*64) +(1*8) +(4*1)=7610

6.1.3.1 Conversions between Octal and Binary

This is fairly straightforward because 8 is the cube of 2; just remember the binary
equivalents for eight octal symbols.
Conversion table

Octal- 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111

Covert 748 to binary


Octal 7 4
Binary(from table) 111 100

Convert 1100110011002 to octal


Group the binary digits into 3s working from right to left.
Add extra 0s to the left and if necessary
Grouped 001 110 011 001 100
binary digits
Octal(from 1 6 3 1 4
table)

Note conversion between decimal are often quicker via octal.

6.1.4 Hexadecimal Numbers (Hexa)

There is another numbers system that is important known as the hexadecimal number
system. This is a number system with a radix of 16. It uses sixteen digits ranging from 0
– 9 and the letters A – F, where A is equivalent to 10 and F is equivalent to 15 in
sequence like that. The place value for hexadecimal numbers goes up in factors of
sixteen Digits for base 10 and Base 16.

Base 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
10

144
Base 0 1 2 3 4 5 6 7 8 9 A B C D E F
16

Place value Table for the hexadecimal number 94616


Place Value 162 = 256 161 = 16 160=1
Hexadecimal digit 9 4 6

A hexadecimal number is usually denoted using 16 as a subscript or capital letter


H to the right of the number. For example, the number 94B can be denoted as 94B 16 OR
94BH
The symbols are 0 to 9 and the letters A to F (which are equivalent to 10 to15 in decimal
i.e. A=10, B=11 etc).and place values between 0 and 15. Conversions

These follows the same pattern used for binary ant octal
(a) Decimal to Hex
Convert 9110 to hex
91/16=5 remainder 11
=B16
5/16=0 remainder 5 Thus;
9110=5B16
(b) Hex to decimal
Convert 6D16 to decimal
Places values 162 161 160
(256) (16) (1)
Hex 0 6 D
Conversion (0*256) +(6*16) +(13*1)

(c ) Conversion between Hex and other bases

Convert 5B16 to binary and octal


A conversion between Hex and Octal is most easy done via binary
Hex to Binary

Hex number 5 B
Binary equivalent 0101 1011

Binary to Octal
Binary 001 011 011
Octal 1 3 3

Note

145
The change from 4 bit to 3-bit binary
Convert 11110010102 to hex
First group the bit into 4s from the right and then convert.
Grouped Binary 0011 1100 1010 digits

Hex 333 C A

d)Binary fractions
Examples of binary fractions are shown below

Binary fraction 2-1=1/2 2-2=1/4 2-3=1/8 2-4=1/16 decimal


.1000 =(1*1/2)+(0*1/4)(+0*1/8+0*1/16) =1/2=0.5
.0100 =1/4=0.25
=(0*1/2)+(1*1/4)+(0*1/8)+(0*1/6)
=(0*1/2)+(0*1/4)+(1*1/8)+(081/16) =1/8=0.125
.0010

=(0*1/2)+(0*1/4)+0*1/8)+1*1/16) =1/16=0.0625
.0001

When converting a number which has both a whole number part and fractional
part, remember to do the two parts separately.

Activity 2
On your own suggest reasons why we use the octal and hexadecimal number systems
………………………………………………………………………………………………………
……………………………………………………………………………………………………..

Having gone through the number system lets get more involved in data
representation by talking about computer arithmetic

146
6.2 Computer Arithmetic
The arithmetic and logic unit of the central processor in a computer performs all its
arithmetic by addition and shifting rather than having different units for subtraction.

(a) Binary Addition


The rules for adding binary numbers are quite simple. There are only four to remember;
0+0=0
0+1=1
1+0=1
1+1=10(0carry 1)
1+1=11(1 carry 1)
(b) Binary Multiplication
Again this is simple. The four rules are
0*0=0
0*1=0
1*0=0
1*1=1
Example
101=510 multiplicand
010=210 multiplier
000
101
000
01010 =1010 product
1 Steps
Start with the most significant digit (one with the highest place value-on the left) of the
multiplier
If it a 1 copy down a row of 0s.
If it is a 0 copy downs a row of 0s
The move to the next digit in the multiplier copying the multiplicand row, or entering 0s
and then shifting one place to the right
Do this for each digit of the multiplier copying the multiplicand, or entering 0s and then
shifting one place to the right
At the end add up all the columns
Binary division
Binary division is not examined but it is best carried out by long division
Negative numbers
There are three common ways of representing negative numbers on Computers
Sign and magnitude (sm)
Ones compliment (1c)
Twos compliment (2c)

147
6.2.1 Sign and Magnitude Codes
Here one bit represents the sign of the number and the other bit represents the size
(magnitude) of the number. Conventionally 1 is negative and 0 is positive. The sign bit
can be at either end of the binary number.
Example (The sign bit is underlined);
1011=-3
01110=+14
Sign and magnitude fractions have the most significant bits as the sign bits also
Binary subtraction
This has more complicated rules
0-0=0
1-0=1
1-1=0
0-1=0, borrow 1
This could be difficult were it not for simple method of subtracting called
complementation.

6.2.3 Ones and Twos Complementation


The reason for using compliments is that it enables to subtract by using a modified form
of addition. Subtraction can be done by adding a negative number, e.g.15+ (-6) gives the
same results as
For 15-6; the Computer work in a similar way.
Ones Compliment
The one compliment (1c) of a binary number is found by simplify reversing the same
bits(NOT gates in logic circuit terms).In 1c the bits have the same place values as binary
numbers except that the most significant bits(the left most bits) represents a negative.

For example, using six bits


Place -31 16 8 4 2 1
values
+13 0 0 1 1 0 1
-13 1 1 0 0 1 0

Notice that the most significant bit =-31


Subtraction using ones complements
Example; 26-15
-31 16 8 4 2 1
Store 15 00 11 1 1
Reverse bits to 1 1 00 0 0
Give-15
Store 26 01 0 1 0
Add-15 and 26 1010 1 0
Add overflow bit

148
=1110 001011

The overflow bit must be added to the unit column of the sum to give right answer. This
is known as end –round or wrap –around carry.
Two Complement
Signed number are stored within a micro computer using the twos complement
Using the two complement notation the most significant bit s of each binary number is used
to indicate the sign of the number. Thus with an 8bit system each number as follows

s 6 - - - - - 0

Ms
S=0 positive number and zero
S=1 for negative numbers
For positive numbers the remaining seven digits then indicate the magnitude of the
number for example
S 26 25 24 23 22 21 20 =weighting
0 0 0 1 0 1 0 1
=+21 decimal
0 1 0 0 1 0 1 0

0 1 1 0 0 0 0 1

For negative number the remaining seven digit represent the magnitude of the number
in twos complement form to obtain the two complement of a number the complete binary
number including the sign bit- is first inverted and the resulting binary value incremented
by 1
+21=00010101
Invert
11101010
+1 increment
Therefore +21=11101011
Similarly
+74=01001010
Invert
10110110
+1 increment
Therefore
+74=10110110

Note that after the complement process the most significant bit is automatically a 1. hence
for an 8-bit system the range of possible numbers is +127 and the maximum negative
number is-128

149
It is now possible to add two binary numbers e.g. the addition of two positive number A
&B to produce sum

A=00101011=+43(dec)
] B=00110010=+50(dec)
………………..
Carry in=01000100
Carry out=00100010
A+B=01011101=+39(dec)

Providing negative numbers can be represented in their twos complement format the
addition operation may be performed and the court two complement signed result to be
obtained. This is perhaps best explained by means of an example, the first example illustrate
the addition of a negative and positive number to produce a negative result the second the
addition of a negative & a negative and positive number to produce positive result in the
third the addition of two negatives number to produce a negative result.

A=00101011=+43
B=11001110=-50
___-_________
Carry in =00010100_Cin
Carry out =00001110
_________________
A+B =11111001=-7
________________
A=11010101=-43
B =00110010=+50
_______________
Carry in=11100000
Carry out = 11110000
________________
A + B= 00000111=+7

150
Addition of 2 bit and a carry in bit
bit1 bit2 bit3 SUM carry
out
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

A =11010101=-43
B =11001110=-50
_______________
Carrying =10111000
Carryout=11011100
_______________

A + B =10100011=-93
The decimal equivalent of the negative result can readily but confirmed by performing
the complement process on the binary result.

6.2.4 The Subtraction Operation


The subtraction of two binary number digits is perhaps best explained by considering
the subtraction of two numbers the decimal system. Consider the following example
A=465
B=-173
BORROW=100
A-B=292
When the second digit is less than or equal to the first digit the subtraction can be
performed straight away and no borrow is required *(e.g. 5 minus3). When the second
digit is greater than the first however, (6 minus 7) it is necessary to borrow a digit from
the next higher position. This is called a borrow in and in the decimal system the borrow
is equal to ten times the magnitude of the other digits in that column. The subtraction
operation in that column become (10+6)-7 which is equal to a difference of 9 with a borrow
to be carried over to the next column. This is called a borrow out and in turn must be
added to the second digit before the latter is subtracted from the first digit.
To summarize, when performing the subtraction operation of two digits it is necessary to
consider borrow in from the previous column. Also if the sum of the second digit and the
borrow in is greater than the first digit then a borrow out is generated.

151
The subtraction of two binary digits and the possible borrow in is therefore shown in the
table above. Bit 2 and the borrow in are first added together and the sum is then
subtracted from bit 1. If this sum is greater than bit1 then a borrow is required. This is
equivalent to two bits in binary system and is in turn added to bit before the subtraction
operation Example
A=00110010=+50
B =00101011=+43
_______________
Borrow in 00011110
Borrow out 00001111
_______________-
A –B= 00000111=+7
_________________

6.2.5.Multiplication of Binary Number


The rule of multiplying 1-bit binary number is straightforward. Since any number
multiplied by 0=0 and any number multiplied by 1=number. We have

0*0=0
0*1=0
1*0=0
1*1=1
If begin with the most significant bit of the multiplier. We multiply each bit of the
multiplicand one bit at a time and write this result in a line. The result is a partial
product. The process is repeated sequentially until all bits of the multiplier are used. The
partial product is then added to give the final product. Example

110 MULTIPLICAND
* 101 multiplier
_______________________________
110
000 } partial product
110
___________________

11110 products
Each partial product is either an exact duplicate of the multiplicand or a line of 0s

6.2.6 Binary Division


As in long division with decimal, binary division is basically a trial and error procedure to
determine how many times a number divides another number (the dividend). Binary division
is much simpler than its decimal counterpart because at each step in the process a divisor
either divides into a group of bits (giving a quotient bit of1) or it doesn’t (giving

152
a quotient bit 0). Whether a divisor a group of bit depends on whether the divisor is
greater than or equal to dividend.

Example; Divided 11110 by110


Long division
110 11
11110
-110
110
110
000

Since 110 is smaller than the value of the first 3bit of the divided (11), the first quotient bit
is 1. Subtracting 110 from 111 and bringing down the next 1 from the dividend gives 011
which is smaller than 110. We drop 0 and consequently the next quotient bit is 1.

6.3 Binary Codes


Digital data is presented, stored and transmitted in groups of binary bits. To convey
information, it’s important to code these bits so that they can also represent numbers,
alphabet and special characters. This codes are referred to as binary codes and can be
grouped into two:
numeric codes-represent numbers, alphanumeric code used to represent character.

6.3.1 Binary Coded Decimal (BCD)


Binary code decimal is a numeric code in which each digit of a decimal number is
represented by a separate group of bit. The most common BCD code is 8-4-2-1. In which
the decimal digit is represented by 4bit binary number. It is called 8-4-2-1 BCD because
the usual weigh associated with 4bit binary number are determined by the position of the
bit within each group.
Example encode decimal number 39 and 107 into BCD

DECIMAL 39 107

8-4-2-1 BCD 0011 1001 0001 0000 0111

153
Decimal 8-4-2-1
Digit BCD Code

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Note that each BCD digit is a weighted code, but multiple coding is not. BCD
representation of number is inefficient as far bit usage is concerned. The reason being that
six patter 1010, 1011,1100,1101,1110 & 1111 are never used i.e. they are redundant; if they
occur then an error has occurred. The advantage of BCD code is that it is easy to convert
to decimal. Another disadvantage is that BCD arithmetic is complex.
8-4-2-1- BCD arithmetic
To add two BCD numbers, we simply add the binary number corresponding to each digit
Example
24=001001000
+13=0000 0011
____________________
37=0011 0111
3 7
A difficult arises when the sum of the two decimal is greater than 9 for in that case one of
the invalid bit patterns is produced.
E.g. 25=00100101
+38=0011 1000
_____________________
63≠010101101
It is also possible that the sum of two 4bit numbers will produce a 5bit number. For
example, 8=1000
+9=1001
____________________
17=10001
5bit, not allowed

154
We recognize in both of these cases that decimal arithmetic required the propagation of a
carry to next higher digit. In the 8-4-2-1 BCD arithmetic, we require to propagate the carry
in, addition we must correct the bit pattern. Thus the rule for BCD addition is as follows
If the sum of two BCD digits is greater than 1001, add 0110 and propagate a carry to the
next most significant sun digit.

The carry is added to the sum bit of the next most significant digit of the sum. The carry
bit is always produced automatically: if the sum bits are 5 bits, the fifth bit is the carry;
otherwise. This bit result when the sum correction is performed. In either case the sum
correction is required. Adding the carry to the next higher order digit may itself produce
a sum greater than 9, requiring that the next correction be repeated.

Example;
a) 25 0010 0101
+17+0000 0111
42 0011 1100 1100>9base 10
+0110 add 6base10
10010
+1
Propagated carry
_________________________________
0100 0010 corrected sum

b) 38 0011 1000
+48 0100 1000
______________________________
86 0111 1000 5bit sum
+1 0110 propagated carry and add 6 base 10
011 0110 corrected sum

6.3.2 Excess-Three: Binary –Decimal-Code


Decimal number Xs3code 8421
0 0011
1 0100
2 0101
3 0110
4 0111
5 1000
6 1001
7 1010
8 1011
9 1100

155
This code is formed by adding the binary equivalent of decimal three to the pure binary
number. It is referred to as the Xs3 code. It has number of advantages, thus it is easy to
calculate, simple to translate into pure binary, and no number is represented by four 0s.
A feature of the excess three codes is that it is self-complementary.

Addition in excess-three code

When the sum of two XS3 number is 9 base 10 or less, the uncorrected sum in the xs3 code
is 3base 10 greater than it should be. This is illustrated below:
Decimal Xs3
3 0110
+3 +0110
________________________________________________
1100
(Uncorrected sum)
The uncorrected Xs3 result is equivalent to 9 base 10 in excess of the correct value. To
compensate for this 3 base 10 is subtracted from the uncorrected sum. When the sum of
the two number is greater than 9 base10, the uncorrected Xs3 sum is 3 base 10 less than
its output to be. To correct the Xs3 result, 3base10 is added to the result as shown below

Decimal Xs3
1011
+9 1100
17 10111
17 + 0011
11010

The simple rule for Xs3 addition is to add 0011 base2 when a carry is generated otherwise
subtract 0011 base 2.

6.3.3 Gray Code


This belongs to the group of cyclic/unit distance codes. Its build up of simple 0 and 1
combination which is progressively reflected as the system build up in magnitude
The first two numbers in the gray code are 0000 and 0001, representing 0 and unity
respectively. The next two numbers are obtained by reflecting the combination, shown
dotted below and adding a’1’ in the next higher digit.

Decimal Gray code


00:00:
00:01
00:11
00:10

156
The table below gives the fifteen member of the group.

Decimal Gray code


0 0000
1 0001
2 0011
3 0010
4 0110
5 0111
6 0101
7 0100
8 1100
9 1101
10 1111
11 1110
12 1010
13 1011
14 1001
15 1000

It not possible to carry out arithmetic process in the gray code it must be converted into pure
binary before carrying out mathematical operation on the data. Unit distance code is more
appropriate for position sensing operation. This is because the error can only be one step
(unit) of system e.g. the binary code can cause a large error. Consider a typical transistor
sequence for pure binary coded plate. When change is from 7 base10 to 8 base10

Binary Decimal Pure


Initial position 7 0111
Expected output 8 1000
During transition 15 1111
Final position 15 1111

Hence if it was a position indicated instrument instead of changing from 7 bases 10 to


8base 10 it could have momentary change from 15 base10 a pronounced error. In gray
code only digit change and hence the error can be of only one digit.

Converting Gray Code into Binary Code


The gray code conversion algorithm gives by bi=gibi+I where bi the ith bit. The
conversion proceeds from left (l=n) to the right (l=0) ex. convert 11101100 from gray to
binary.

157
Converting Binary to Gray Code

The algorithm any bit is given by gi=bi XOR bi (+1) where is the ith bit and (l+1) is the
next bit (msb).if l=5 then gi=bi XOR bi+1 go =bi XOR bi+1 go =b2 be, gi=bi XOR b2, go=bi
bi.
Convert BCD into Decimal

Take the BCD number and divide it into groups of 4digit each starting from the least
significant bit. If the last group isn’t composed of four digits add 0 to the left, then write
the decimal equivalent.
In case you don’t remember the exact decimal equivalent you may treat the BCD like a
pure gray number of the digit, but this is the only true for the group of four bit not for the
whole number
Converting A Decimal Number into Its Standard BCD
Remember that each decimal digit in BCD represented by four binary bits in BCD, hence
to convert into BCD, write each digit in its equivalent BCD number remembering the
order. For example, 4 5 9
0100 0101 1001

6.3.4 Alphanumeric Codes


Digital computers handle both alphabetical and numerical data, hence the need to have
code to represent these characters, numeral and special characters. In order to transmit a
complete text in the English language the letters to be translated could be: Codes both
capital and small letters of the alphabet (52 codes).
Codes for digits 0-9(10 codes)
Codes for typewriter instruction (this required for the purposes of electronic type writer
to function properly, they include but not limited to instruction such as carriage return,
linefeed, and space (3 codes).
Codes word for punctuation marks such as “; , . : (5 codes for this example)
Code for any other special character such as division, addition, subtraction, multiplication
(4 codes).
The total number of codes for this example (52+10+3+5+4) is 74.
The number of bits n required can be determined by solving the
equation 2n = 74
, n log22=log10 74
, n= log10 74/ log22
From the above it can be seen that if we have to print then we require more than 6 bits. A
range of codes have to been developed for the purpose of text transmission popular one
being the ASCII teleprompter code. It makes use of the seven bits to code the character
and hence the total number of codes is128 an extra bit is added for evenly parity checking.
However, to take care of the Japanese and Chinese code as be adopted that makes use of
16 bits with ASCII code being a subset of the UNICODE.

158
When converting a number which has both a whole number part and

fractional part, remember to do the two parts separately.

Activity 2

On your own suggest reasons why we use the octal and hexadecimal number
systems

……………………………………………………………………………………………………..
……………………………………………………………………………………………………..

Having gone through the number system lets get more involved in data
representation by talking about computer arithmetic

6.2 Computer Arithmetic


The arithmetic and logic unit of the central processor in a computer performs all its
arithmetic by addition and shifting rather than having different units for subtraction.

(a) Binary Addition

The rules for adding binary numbers are quite simple. There are only four to
remember;

0+0=0

0+1=1

159
1+0=1

1+1=10(0carry 1)

1+1=11(1 carry 1)

(b) Binary Multiplication

Again this is simple. The four rules are

0*0=0

0*1=0

1*0=0

1*1=1

Example
101=510 multiplicand

010=210
multiplier

000

101

000

01010 =1010
product

1
Steps

160
Start with the most significant digit (one with the highest place value-on the left) of the
multiplier

If it a 1 copy down a row of 0s.

If it is a 0 copy downs a row of 0s

The move to the next digit in the multiplier copying the multiplicand row, or entering
0s and then shifting one place to the right

Do this for each digit of the multiplier copying the multiplicand, or entering 0s and
then shifting one place to the right

At the end add up all the columns

Binary division

Binary division is not examined but it is best carried out by long


division

Negative numbers

There are three common ways of representing negative numbers on


Computers

Sign and magnitude (sm) Ones compliment (1c) Twos compliment (2c)

6.2.1 Sign and Magnitude Codes


Here one bit represents the sign of the number and the other bit represents the size
(magnitude) of the number. Conventionally 1 is negative and 0 is positive. The sign bit
can be at either end of the binary number.

Example (The sign bit is underlined);

1011=-3

161
01110=+14

Sign and magnitude fractions have the most significant bits as the sign bits also

Binary subtraction

This has more complicated rules

0-0=0

1-0=1

1-1=0

0-1=0, borrow 1

This could be difficult were it not for simple method of subtracting called
complementation.

6.2.3 Ones and Twos Complementation


The reason for using compliments is that it enables to subtract by using a modified form
of addition. Subtraction can be done by adding a negative number, e.g.15+ (-6) gives the
same results as for 15-6; the computer work in a similar way.

One Compliment

The one compliment (1c) of a binary number is found by simplify reversing the same bits
(NOT gates in logic circuit terms). In 1c the bits have the same place values as binary numbers
except that the most significant bits (the left most bits) represents a negative.

162
For example, using six bits

Place -31 16 8 4 2 1
values

-13 1 1 0 0 1 0

Notice that the most significant bit =-31

Subtraction using ones complement

Example; 26-15

-31 16 8 4 2 1

Store 15 0 0 1 1 1 1

Reverse bits to 11 0 00 0

Give-15

Store 26 0 1 0 1 0

Add-15 and 26 1010 1 0

Add overflow bit

=1110 001011

The overflow bit must be added to the unit column of the sum to give right
answer. This is known as end –round or wrap –around carry.

163
Two Complement

Signed number are stored within a micro-computer using the twos complement

Using the two complement notation the most significant bit s of each binary number is
used to indicate the sign of the number. Thus with an 8bit system each number as
follows

s 6 - - - - - 0

Ms

S=0 positive number and zero

S=1 for negative numbers

For positive numbers the remaining seven digits then indicate the magnitude of the
number for example

S 26 25 24 23

22 21 20
=weighting

0 0 0 1 0 1 0 1

=+21 decimal

0 1 0 0 1 0 1 0

0 1 1 0 0 0 0 1

164
For negative number the remaining seven digit represent the magnitude of the number
in twos complement form to obtain the two complement of a number the complete binary
number including the sign bit- is first inverted and the resulting binary value
incremented by 1

+21=00010101

Invert

11101010

+1 increment

Therefore
+21=11101011

Similarly

+74=01001010

Invert

10110110

+1 increment

Therefore

+74=10110110

Note that after the complement process the most significant bit is automatically a 1, hence
for an 8 bit system the range of possible numbers is +127 and the maximum negative
number is-128.
It is now possible to add two binary numbers e.g. the addition of two positive number A
&B to produce sum

165
A=00101011=+43(dec)

] B=00110010=+50(dec)

……………….. Carry in=01000100


Carry out=00100010

A+B=01011101=+39(dec)

Providing negative numbers can be represented in their twos complement format the
addition operation may be performed and the court two complement signed result to be
obtained. This is perhaps best explained by means of an example the first example
illustrates the addition of a negative and positive number to produce a negative result
the second the addition of a negative & a negative and positive number to produce
positive result in the third the addition of two negatives number to produce a negative
result

A=00101011=+43

B=11001110=-50

Carry in =00010100_Cin

Carry out =00001110

A+B =11111001=-7

A=11010101=-43

B =00110010=+50

Carry in=11100000

Carry out = 11110000

166
A + B= 00000111=+7

Addition of 2 bit and a carry in bit

Bit1 Bit2 Bit3 SUM carry


out
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1

A =11010101=-43

B =11001110=-50

Carrying =10111000

Carryout=11011100

A + B =10100011=-93

The decimal equivalent of the negative result can readily but confirmed by
performing the complement process on the binary result.

6.2.4 The Subtraction Operation


The subtraction of two binary number digits is perhaps best explained by considering
the subtraction of two numbers the decimal system. Consider the following example

A=4
65

167
B=-
173

BORROW=1
00

A-
B=292

When the second digit is less than or equal to the first digit the subtraction can be performed
straight away and no borrow is required *(e.g. 5 minus3). When the second digit is greater
than the first however, (6 minus 7) it is necessary to borrow a digit from the next higher
position. This is called a borrow in and in the decimal system the borrow is equal to ten times
the magnitude of the other digits in that column. The subtraction operation in that column
become (10+6)-7 which is equal to a difference of 9 with a borrow to be carried over to the
next column. This is called a borrow out and in turn must be added to the second digit before
the latter is subtracted from the first digit.

To summarize, when performing the subtraction operation of two digits it is necessary


to consider borrow in from the previous column. Also if the sum of the second digit and
the borrow in is greater than the first digit then a borrow out is generated.

The subtraction of two binary digits and the possible borrow in is therefore shown in the
table above. Bit 2 and the borrow in are first added together and the sum is then
subtracted from bit 1. If this sum is greater than bit1 then a borrow is required. This is
equivalent to two bits in binary system and is in turn added to bit before the subtraction
operation

Example,

A=00110010=+50

B =00101011=+43

Borrow in 00011110

168
Borrow out 00001111

A –B= 00000111=+7

6.2.5 Multiplication of Binary Number


The rule of multiplying 1-bit binary number is straightforward. Since any number
multiplied by 0=0 and any number multiplied by 1=number. We have

0*0=0

0*1=0

1*0=0

1*1=1

If begin with the most significant bit of the multiplier. We multiply each bit of the
multiplicand one bit at a time and write this result in a line. The result is a partial product.
The process is repeated sequentially until all bits of the multiplier are used. The partial
product is then added to give the final product.

Example

110
MULTIPLIC AND

*
101
multiplier

110

169
0 } partial product

110

11110 products

Each partial product is either an exact duplicate of the multiplicand or a line of 0s

6.2.6 Binary Division


As in long division with decimal, binary division is basically a trial and error procedure
to determine how many times a number divides another number (the dividend). Binary
division is much simpler than its decimal counterpart because at each step in the process
a divisor either divides into a group of bits (giving a quotient bit of1) or it doesn’t (giving
a quotient bit 0). Whether a divisor a group of bit depends on whether the divisor is
greater than or equal to dividend.

Example;
Divided 11110 by110

Long division

110 11
11110

-110

110

110

000

Since 110 is smaller than the value of the first 3bit of the divided (11), the first quotient bit is
1. Subtracting 110 from 111 and bringing down the next 1 from the dividend gives 011 which
is smaller than 110. We drop 0 and consequently the next quotient bit is 1

170
6.3 Binary Codes
Digital data is presented, stored and transmitted in groups of binary bits. To convey
information, it’s important to code these bits so that they can also represent numbers,
alphabet and special characters. This codes are referred to as binary codes and can be
grouped into two:

• Numeric codes-represent numbers


• Alphanumeric code used to represent character.

6.3.1 Binary Coded Decimal (BCD)


Binary code decimal is a numeric code in which each digit of a decimal number is
represented by a separate group of bit. The most common BCD code is 8-4-2-1. In which
the decimal digit is represented by 4bit binary number. It is called 8-4-2-1 BCD because
the usual weigh associated with 4bit binary number are determined by the position of
the bit within each group.

Example encode decimal number 39 and 107 into BCD

DECIMAL 39 107
8-4-2-1 BCD 0011 1001 0001 0000 0111

Decimal Digit 8-4-2-1


BCD Code
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Note that each BCD digit is a weighted code, but multiple coding is not. BCD
representation of number is inefficient as far bit usage is concerned. The reason being
that six patter 1010,

171
1011,1100,1101,1110 & 1111 are never used i.e. they are redundant; if they occur then an
error has occurred. The advantage of BCD code is that it is easy to convert to decimal.
Another disadvantage is that BCD arithmetic is complex.

8-4-2-1- BCD arithmetic

To add two BCD numbers, we simply add the binary number corresponding to each
digit

Example,

24=001001000

+13=0000 0011

37=0011 0111
3 7

A difficult arises when the sum of the two decimal is greater than 9 for in that case
one of the invalid bit patterns is produced.

E.g. 25=00100101

+38=0011 1000

63≠010101101

It is also possible that the sum of two 4bit numbers will produce a 5bit number. For
example
8=1000

+9=1001
____________________
17=10001

172
5bit, not allowed

We recognize in both of these cases that decimal arithmetic required the propagation of
a carry to next higher digit. In the 8-4-2-1 BCD arithmetic, we require to propagate the
carry in, addition we must correct the bit pattern. Thus the rule for BCD addition is as
follows

If the sum of two BCD digits is greater than 1001, add 0110 and propagate a carry to the
next most significant sun digit

The carry is added to the sum bit of the next most significant digit of the sum. The carry
bit is always produced automatically: if the sum bits are 5 bits, the fifth bit is the carry;
otherwise. This bit result when the sum correction is performed. In either case the sum
correction is required. Adding the carry to the next higher order digit may itself produce
a sum greater than 9, requiring that the next correction be repeated.

Example,

a) 25 0010 0101

+17+0000 0111

42 0011 1 1 0 0 1100>9base 10

+0110 add 6base10

10010 +1

Propagated carry

_________________________________

0100 0010 corrected sum

173
b) 38 0011 1000

+48 0100 1000

86 0111 1000 5bit sum

6.3.2 Excess-Three: Binary –Decimal-Code

Decimal Xs3code 8421


number
0 0011
1 0100
2 0101
3 0110
4 0111
5 1000
6 1001
7 1010
8 1011
9 1100

This code is formed by adding the binary equivalent of decimal three to the pure binary
number. It is referred to as the Xs3 code. It has number of advantages, thus it is easy to
calculate, simple to translate into pure binary, and no number is represented by four 0s.
A feature of the excess three codes is that it is self-complementary.

174
Addition in excess-three code

When the sum of two XS3 number is 9 base 10 or less, the uncorrected sum in the xs3
code is
3base 10 greater than it should be. This is illustrated below

Decimal Xs3

3 0110

+3 +0110
________________________________________________

1100

(Uncorrected sum)

The uncorrected Xs3 result is equivalent to 9 base 10 in excess of the correct value. To
compensate for this 3 base 10 is subtracted from the uncorrected sum. When the sum of the
two number is greater than 9 base10, the uncorrected Xs3 sum is 3 base 10 less than its output
to be. To correct the Xs3 result, 3base10 is added to the result as shown below

Decimal Xs3

10
11

+9 1100

17 10111

17 +0011

1101
0

175
The simple rule for Xs3 addition is to add 0011 base2 when a carry is generated
otherwise subtract 0011 base 2.

6.3.3 Gray Code


This belongs to the group of cyclic/unit distance codes. Its build up of simple 0 and 1
combination which is progressively reflected as the system build up in magnitude.

The first two numbers in the gray code are 0000 and 0001, representing 0 and unity
respectively. The next two numbers are obtained by reflecting the combination, shown
dotted below and adding a’1’ in the next higher digit.

Decimal Gray code

00:00:

00:01

00:11

00:10

176
The table below gives the fifteen member of the group.

Decimal Gray Code


0 0000
1 0001
2 0011
3 0010
4 0110
5 0111
6 0101
7 0100
8 1100
9 1101
10 1111
11 1110
12 1010
13 1011
14 1001
15 1000

It not possible to carry out arithmetic process in the gray code it must be converted into
pure binary before carrying out mathematical operation on the data. Unit distance code
is more appropriate for position sensing operation. This is because the error can only be
one step (unit) of system e.g. the binary code can cause a large error. Consider a typical
transistor sequence for pure binary coded plate. When change is from 7 base10 to 8 base10

Binary Decimal Pure

Initial position 7 0111

Expected output 8 1000

During transition 15 1111

Final position 15 1111

177
Hence if it was a position indicated instrument instead of changing from 7 bases 10 to
8base 10 it could have momentary change from 15 base10 a pronounced error. In gray
code only digit change and hence the error can be of only one digit.

Converting Gray Code into Binary Code

The gray code conversion algorithm gives by bi=gibi+I where bi the ith bit. The
conversion proceeds from left (l=n) to the right (l=0) ex. convert 11101100 from gray to
binary

Converting Binary to Gray Code

The algorithm any bit is given by gi=bi XOR bi (+1) where is the ith bit and (l+1) is the
next bit (msb).if l=5 then gi=bi XOR bi+1 go =bi XOR bi+1 go =b2 be, gi=bi XOR b2, go=bi
bi

Convert BCD into Decimal.

Take the BCD number and divide it into groups of 4digit each starting from the least
significant bit. If the last group isn’t composed of four digits add 0 to the left, then write
the decimal equivalent.

In case you don’t remember the exact decimal equivalent you may treat the BCD like a
pure gray number of the digit, but this is the only true for the group of four bit not for
the whole number

Converting A Decimal Number into its Standard BCD

Remember that each decimal digit in BCD represented by four binary bits in BCD, hence to
convert into BCD, write each digit in its equivalent BCD number remembering
the order. For example, 4 5 9

0100 0101 1001

178
6.3.4 Alphanumeric Codes
Digital computers handle both alphabetical and numerical data, hence the need to have
code to represent these characters, numeral and special characters. In order to transmit
a complete text in the English language the letters to be translated could be:

Codes both capital and small letters of the alphabet (52 codes). Codes for digits 0-9(10
codes)
Codes for typewriter instruction (this required for the purposes of electronic type writer
to function properly, they include but not limited to instruction such as carriage return,
linefeed, and space (3 codes).

Codes word for punctuation marks such as “ ; , . : (5 codes for this


example)

Code for any other special character such as division, addition, subtraction, (4
multiplication codes).

The total number of codes for this example (52+10+3+5+4) is 74.

The number of bits n required can be determined by solving the equation

2n = 74

, n log22=log10 74

, n= log10 74/ log22

From the above it can be seen that if we have to print then we require more than 6 bits.
A range of codes have to been developed for the purpose of text transmission popular
one being the ASCII teleprompter code. It makes use of the seven bits to code the
character and hence the total number of codes is128 an extra bit is added for evenly parity
checking.

However, to take care of the Japanese and Chinese code as be adopted that makes use of
16 bits with ASCII code being a subset of the UNICODE.

179
Summary
In this topic you have learnt about data representation methods and how to represent
the data using various number systems. We have also covered the steps of converting
from one number system to another. We then concluded this topic by practicing in
computer arithmetic.

As we finish this module, let us see how well you have understood topic 6.

Self-Check

a). Explain the two types of signals. (2marks)

b). Differentiate between (4 marks)

• Octal and decimal number systems


• Binary and hexadecimal number systems

c). Convert the following binary numbers to their decimal equivalents (6marks)

1011102 11.1012 01102

d). Convert the following decimal numbers to their binary equivalents (6 marks)

78910 57010 7.12510

e). Convert the octal numbers 3218 and 14138 to its binary equivalent (6marks)

180
f). Convert the following hexadecimal numbers into their binary equivalent (6marks)

CDFF3116 24716

Scoreboard

Marks Remarks
25–30 Excellent
20–25 Very Good
15–20 Good
10–15 Fair
0- 10 Go through the topic again

Further Reading

Tanen –baum, A.S. (1996). Computer networks. New Delhi: Prentice Hall

Mburu, S., & Chemwa, G. (2010). Computer Studies: Book 3. London: Longhorn
publishers

Learning Outcomes

You have now completed topic six, the learning outcomes are listed below;

Check (√) the column which reflects your understanding of the various concepts about
writing.

181
S/No Learning Outcome Sure Not Sure
1 I can now explain what data
representation is
2. I can discuss the various number systems
for representing data
3. I can carry out conversions of data in various
number systems

7.0 References

Abolhassan, F. (ed) (2016). The Drivers of Digital Transformation.

Abou-Nasr, M. (Ed), Lessmann, S. (ed), Stahlbock, R. (ed), Weiss, G. M. (ed) (2015). Real
World Data Mining Applications.

Abramowicz, W. (Ed) (2015). Business Information Systems Workshops.

Beissel, S. (2016). Mobile Marketing Channel.

Benbya, H. (2015). Exploring the Design and Effects of Internal Knowledge Markets.

Blöbaum, B. (Ed) (2016). Cyber Security Investments.

Bongiorno, G. (Ed), Rizzo, D. (Ed) and Vaia, G. (Ed) (2016). CIOs and the Digital
Transformation.

Fürber, C. (2016) Data Quality Management with Semantic Technologies


: Information System at the Lithuanian University of Agriculture

Kassel, S. (Ed) and Wu, B. (Ed) (2016). Software Engineering Education Going Agile.

182
Kordha T, E., Sevrani, K. and Gorica, K. (2015). Information Society Developmentthrough
ICT Market Strategies.

Mancini, D. (Ed), Dameri, R. P. (Ed) and Bonollo, E. (Ed) (2016). Agile Software
Development Teams.

Marx Gómez, J. (Ed), Scholtz, B. (Ed) (2016). InformationTechnology in Environmental


Engineering

Mburu, S., and Chemwa, G. (2010). Computer Studies: Book 4. London: Longhorn
publishers

Nöhren, M. (2016). Enterprise Software Sourcing Performance

Ricciardi, F. (Ed) and Harfouche, A. (Ed) (2016.). Information and Communication


Technologies in Organizations and Society

Rossignoli, C. (Ed), Gatti, M. (Ed) and Agrifoglio, R. (Ed) (2016) Organizational


Innovation and Change.

Schmidt, C. (2016). Emerging Trends in Information Systems.

Sharma, C. (2015).Business Process Transformation

Shi, Y., Zhang, L., Tian, Y. and Li, X. (2015). Intelligent Knowledge

Shishkov, B. (Ed) (2015). Business Modeling and Software Design

Spohrer, K. (2016). Collaborative Quality Assurance in Information Systems Development .

Stallings H, S. (1988). Computers–The User Perspective, Times mirror


Stases, M. (2002). Computer based System for Students Admission and Students Records

Strang, K. (Ed) (2015). The Palgrave Handbook of Research Design in Business and
Management.

Tanen –baum, A.S. (1996). Computer Networks. New Delhi: Prentice Hall.

183
Wang, W and Parker, R. C. (2002) Office 2000 for Windows. New York: Microsoft

Willcocks, L. P. (Ed), Sauer, C. (Ed) and Lacity, M. C. (Ed) (2016). Strengthening


Information and Control Systems.

Wrycza, S. (Ed) (2015). Information Systems:Development,Applications,Education.

As we conclude this module herein attached find sample exam papers to


guide you during revision of the exams in this module.

184

You might also like