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

Data representation Methodddd (2)

The document provides an overview of data representation methods in computers, focusing on various number systems including decimal, binary, octal, and hexadecimal. It explains how data is represented in binary form, the significance of bits and bytes, and the process of converting between different number bases. Additionally, it details the methods for converting decimal numbers with fractions to binary and vice versa.

Uploaded by

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

Data representation Methodddd (2)

The document provides an overview of data representation methods in computers, focusing on various number systems including decimal, binary, octal, and hexadecimal. It explains how data is represented in binary form, the significance of bits and bytes, and the process of converting between different number bases. Additionally, it details the methods for converting decimal numbers with fractions to binary and vice versa.

Uploaded by

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

INTRODUCTION TO INFORMATION TECHNOLOGY 2018

Chapter 4
Data representation method
Objectives:
 To understand how really data represented, flow, stored and processed inside the
computer.
 To know the different coding systems & unit of data representation.
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 that can have a corresponding electrical signal.

Number System
A number system is a set of symbols used for counting. There are various number systems, such
as: Decimal, Binary, octal-decimal, hexadecimal etc.

a) The Decimal Number System


The Decimal number system is based on the ten different digits (or symbols) 0,1,2,3,4,5,6,7,8,9.
We say it is a base ten number system
Though it is widely used, it is inconvenient for computer to represent data. So we need another
number system.

b) The Binary number system


Binary number system is based on the two different digits; 0 and 1;
It is important to note that every decimal number system has its equivalent binary number;
Conversion from binary to its equivalent decimal and from decimal to its equivalent binary is
possible; Operation on binary number system is also possible
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Decimal 0 1 2 3 4 5 6 7 8 9

The most elementary form to organize data within a computer (an electronic device) is in the
form of a code which utilizes the “ON” and “OFF” states of electric switches or there is
“current” and “no current” condition of the electronic components;
We see that the nature of the electronic devices has similarity with the binary number system in
that both represent only two elementary states;

Organized By IT Department Page 1


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

It is therefore convenient to use binary number system to represent data in a computer;


An “ON” corresponds to a 1; An “OFF” corresponds to a 0;
In the computer “ON” is represented by the existence of a current and “OFF” is represented by
non existence of current
On a magnetic disk, the same information is stored by changing the polarity of magnetized
particles on the disk’s surface.

c) Octal number System (base 8) (Oct)


 It uses 8 symbols 0-7 to represent numbers;
 Like binary number system it is complete number system.
Example: 77 in octal equals 49 in decimal and 111111 in binary.
When we compare the octal with the decimal, 0-7 in octal is the same as 0-7 in decimal but 10
in octal is not the same as 10 in decimal because 10 in octal holds the position of 8 in decimal,
off course 10 in octal is the same as 8 in decimal.

d) Hexadecimal number system (16) (hex)


 It uses 16 symbols to represent numbers. But for the numbers greater than 15 they
represented in terms of the 16 symbols. For example the decimal number 16 represented as 10,
20 as 14, 30 as 1E and so on. These symbols are 0,1,…9,A,B,C,D,E,F
 When we compare the hexadecimal with decimal, 0-9 in hexadecimal is the same as 0-9
in decimal but 10 in hexadecimal is not the same as 10 in decimal, off course 10 in
hexadecimal is equal to 16 in decimal because it holds the position of 16 in decimal.
Example
DECIMAL OCTAL BINARY HEXADECIMAL
0 0 0 0
3 3 11 3
8 10 1000 8
10 12 1010 A
16 20 10000 10

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;

Organized By IT Department Page 2


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

i) B IT
 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;
ii) 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
iii) 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.
Conversion from one Base to Another
The values that numbers have with a 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, the

Organized By IT Department Page 3


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

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 135 is in base 10 number system.
 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.
 The binary number 1101 may be expanded as
(1101)2 =1*23+1*22+0*21+1*20 = 8+4+0+1
= (1*8)+(1*4)+(0*2)+(1*1) = 1310
*A number X1 X2 X3 …Xn in base M can be expanded as
(X0 X1 X2 X3 …..Xn)M=X0*mn-1+X1*mn-2X2*mn-3+ …Xd-1*m1+Xnm0 in base 10

Conversion from decimal (base 10) to other base (base M)


To convert a decimal number X to a number in base m, divide X by m, store the
remainder, again divide the quotient by M, store the remainder, and continue until the
quotient is 0. And concatenate (collect) the remainders starting from the last up to the
first.
Ex.1 Convert 5610 to base two (binary) EX. 3. Convert 3010 to base sixteen
X=56 M=2 (hexadecimal)
5610 =1110002 3010=1E16
EX.2 Convert 7810 to base eight (Octal) Convert 1610 to base sixteen
7810=1168 (hexadecimal)
1610=A016

Conversion from base M to base 10 (decimal)


To convert a number X consists of digits X1 X2 X3 …Xn in base m to decimal; simply
expand the number with base M. That is
(X1X2X3…Xn) m =X1*mn-1+X2*mn-2 +X3*mn-3+...+ Xi*mn-i+… Xn-1m1+Xn*m0
=Y10
Example 3. convert (101)8 to decimal =65
1. Convert (1001001)2 to decimal=73 4. convert (A1B) 16 to decimal= 2587
2. convert (234)8 to decimal =156 5. covert (101)16 to decimal =257

Conversion from binary (base2) to Octal (base 8) or hexadecimal (base16)


and vice versa
To convert a number in binary to octal group three binary digits together starting from
the last digit (right) and if there are no enough digits add zeros to the front end (left)
and find the corresponding Octal of each group.
Example. Convert 1001001 to octal 1001001=001,001,001

Organized By IT Department Page 4


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

= 1118 Convert 101101001 to octal


101101001 =101,101,001
=5518
To convert binary to hexadecimal group four binary digits together starting from right
and if there are no enough digits add zeros at the left.
EX. Convert 111100100 to hexadecimal Convert 111001111 to Hexadecimal
111100100 =0001 1110 0100 111001111 =0001 1100 1111
=1 14 4 =1 12 15
=1 E 4 =1 B F
= 1E416 =(1BF)16
To convert from Octal to binary, convert each octal digit to its equivalent 3 bit binary
starting from right.
EX. Convert (675) eight to binary Convert 231eight to binary
675eight =110 111 101 231eight = 010 011 001
=110111101two =10011001two
To convert from Hexadecimal to binary convert each hex. Digit to its equivalent 4-bit
binary starting from right.
Ex. Convert 23416 to binary Convert 2AC to binary
23416 =0010 0011 0100 2AC16 =0010 1010 1100
= 10001101002 =10101011002

Conversion from Octal to hexadecimal and vice versa


To convert from Octal to hexadecimal, first we have to convert to binary and the binary
to hexadecimal. To convert from hexadecimal to Octal, first we have to convert to binary
and then the binary to Octal.

EX.1. Convert 2358 to hexadecimal Convert 1A to Octal


2388=010 011 101 1A=0001 1010
=0000 1001 1101 =000 011 010
= 0 9 13 =0 3 2
=9D16 =328

Summary of conversion from one base to another base


From base To base Method
2 10 Expand binary number in powers of 2
10 2 Factor the decimal number by 2
2 8 Group 3 binary digits together
8 2 Each Octal digit is converted to 3 binary digits
2 16 Group 4 binary digits together
16 2 Each hexadecimal digit is converted to 4 binary digits
8 10 Go from 8…….2…….10
10 8 Go from 10 …..2……..8
16 10 Go from 16 …….2…….10

Organized By IT Department Page 5


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

10 16 Go from 10 …….2…….16
8 16 Go from 8 …….2…….16
16 8 Go from 16 …….2…….8

Converting decimal number with fractions to Binary.


 First change the integer part to its equivalent binary.
 Multiply the fractional part by 2 and take out the integer value, and again multiply
the fractional part of the result by 2 and take out the integer part, continue this
until the product is 0.
 Collect the integer values from top to bottom & concatenate with the integer part.

Ex. A) Convert 12.2510 to binary 1100.01


B) Convert 3.1875 to binary 11.0011

Converting Binary with fraction to decimal.


To convert a binary number Y1Y2Y3Y4Yn.d1d2d3..dm to decimal first convert the integer
part to decimal by using
y1 y2 y3 y4…yn=y1*2n-1+y2*2n-2+….yj*2n-j+….+yn-1*21+yn*20=Q and convert the
fractional part to decimal by using
d1d2d3…dm=d1*2-1+d2*2-2+d3*2-3+…+dj*2-j+..+dm*2-m=R
then decimal equivalence of y1 y2 y3 y4…..yn.d1d2…dm will be Q+R where Q is the
integer part and R is the fractional part.

Ex1 : Convert 11001-0101 to decimal =>11001.0101 = 25.3125.


11001 = 1x24 + 1x23 Ex 2: Convert 1000.1 to decimal
2 1 0
+0x2 +0x2 +1x2 = 16+8+1= 25= Q 1000 = 1+23 +0+0+0=8
0101 =0x2-1+1x2-2+0x2-3+1x2-4 1= 1x2-1=½ = 0.5
= 0+¼+0+1/16 = 0.3125 = R 1000.1 = 8.510

Conversion from Octal or hexadecimal with fraction to binary.


 Convert each Octal/hexadecimal digit to its equivalent 3/4-bit binary digit.
 Collect the binary sequences by separating the integer part binaries from the
fractional part binaries with point (.)

Conversion from Octal with fraction to hexadecimal


 To convert from Octal to hexadecimal, first convert the Octal to binary and then the
binary to hexadecimal

Conversion from Hexadecimal with fraction to octal


 To convert from hexadecimal to Octal, first convert the hexadecimal to binary and
then the binary to Octal.

Organized By IT Department Page 6


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

Conversion from octal/hexadecimal with fraction to decimal.


 To convert from Octal/hexadecimal to decimal, first convert to binary and –then the
binary to decimal.
Binary Arithmetic
Computer understands only the language of binary numbers. Therefore, the machine
performs what is called binary arithmetic (binary computation).

Binary addition
Binary addition operates by the same rule as decimal addition, except that it is simpler. A
carry to the next higher order (or more significant) position occurs when the sum is
decimal 2, that is, binary 10. Therefore, the binary addition rules may be written as
follows:
0+0=0
0+1=1
1+0=1
1+1=0 plus a carry of 1 into the next position
1+1+1=1 plus a carry of 1 into the next position.
The last case occurs when the two binary digits in a certain position are 1s and there is a
carry from the previous position.
Example1:
6+7 =13
110+111=1101
Example2
19+31+10=60
10011 +11111+1010=111100

Binary Subtraction
It operates by the same rule as decimal subtraction. The rule is as follows;
0-0=0
1-0=1
1-1=0
10-1=1

Organized By IT Department Page 7


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

Example:
11100 28 101101 45 11001.011
- 11010 -26 - 111 -7 - 111.110
00010 =2 101100 =38 10001.101

Binary Multiplication:
- It is a very simple process that operates by the following obvious rulers:
(a) Multiplying any number by 1 rules the multiplicand unchanged
0x1=0
1x1=1
(b) Multiplying any number by 0 produces 0
0x0=0
1x0=0

Binary division
That is, the process for dividing one binary number (the dividend) by another (the
divisor) is based on the rules for binary subtraction and multiplication and Similar to
decimal division
Ex 1111101 11001
11001 101
11001
11001
00000
1111101 ÷ 11001 = 101

Representation of Negative numbers


There are different ways of representing negative numbers in a computer.

a) Sign- magnitude representation.


In signed binary representation, the left-most bit is used to indicate the sign of the
number. Traditionally, 0 is used to denote a positive number and 1 is used to denote a
negative number. But the magnitude part will be the same for the negative and positive
values. For example 11111111 represents-127 while, 01111111 represents + 127. We
can now represent positive and negative numbers, but we have reduced the maximum
magnitude of these numbers to 127.

Organized By IT Department Page 8


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

In a 5- bit representation we use the first bit for sign and the remaining 4- bits for the
magnitude. So using this 5 bit representation the range of number that can be represented
is from -15 (11111) to 15(01111)
Ex1 represent-12 using 5-bi sign magnitude representation
- first we convert 12 to binary i. e 1100
Now -12 = 11100
Ex2 Represent –24 using 8-bits
24=00011000
-24 = 1001100
In general for n-bit sign –magnitude representation the range of values that can be
represented are – (2 n-1-1) to (2 n-1-1).
i.e. 2 n-1 + 1 to 2 n-1 –1
Note: In sign magnitude representation zero can be represented as 0 or -0. This
representation has two problems one is it reduces the maximum size of magnitude, and
the second one is speed efficiency to perform arithmetic and other operations.
For sign magnitude representation, correct addition and subtraction are relatively
complex, involving the comparison of signs and relative magnitude of the two numbers.
The solution to this problem is called the two’s complement representation.

b) One’s complement.
In one’s complement representation, all positive integers are represented in their correct
binary format. For example +3 is represented as usual by 00000011. However, its
complement, -3, is obtained by complementing every bit in the original representation.
Each 0 is transformed into a1 and each 1 into a0. In our example, the one’s complement
representation of -3 is 11111100.
Ex: +2 is 00000010
-2 is 11111101
Note that in this representation positive numbers start with a 0 on the left, and negative
numbers start with a 1 on the left most bit.
Ex1. add –3 and 3 with word size 4
3 = 0011
-3=1100
sum =1111 (=0)
Ex2. Add -4 and +6
- 4 is 11111011
+ 6 is 00000110
the sum is (1) 00000001 the one in the parenthesis is the external carry.
Where 1 indicates a carry. The correct result should be 2 or 00000010.

Organized By IT Department Page 9


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

In one’s complement addition and subtraction, if there is an external carry it should be


added to get the correct result. This indicates it requires additional circuitry for
implementing this operation.

c) Two’s Complement Representation


In two’s complement representation, positive numbers are represented, as usual, in singed
binary, just like in one’s complement. The difference lies in the representation of
negative numbers. A negative number represented in two’s complement is obtained by
first computing the one’s complement and then add one.

Ex: +3 is represented in signed binary as 00000011


Its one’s complement representation is 11111100.
The two’s complement is obtained by adding one.
It is 11111101.
Ex let’s try addition.
(3) 00000011
+ (5) +00000101
(8) 0001000
The result is correct
Ex2. Let’s try subtraction
(3) 00000011
(-5) + 111111011
11111110
Ex2 add +4 and -3(the subtraction is performed by adding the two’s complement).
+4 is 00000100
-3 is 111111101
The result is [1] 000000001

If we ignore the external carry the result is 00000001 ( i. e 1 In decimal). This is the
correct result. In two’s complement, it is possible to add or subtract signed numbers,
regardless of the sign. Using the usual rules of binary addition, the result comes out
correct, including the sign. The carry is ignored. One’s complement may be used, but if
one’s complement is used, special circuitry is required to “ correct the result”.

Carry and overflow


Ex (128) 10000000
+(129) 10000001

Organized By IT Department Page 10


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

[257] =(1) 00000001


Where 1 indicates a carry. The result requires a ninth bit (bit 8, since the right- most bit
is 0). It is the carry bit.
The two’s complement representation has one anomaly not found with sign magnitude or
one’s complement. The bit pattern 1 followed by N-1 zeros is its own 2’s complement.
To maintain sign bit consistency, this bit pattern is assigned the value –2N for example,
for 8-bit word,
-128 = 10000000
its 1’s complement =01111111
+1
=100000000 = -128
Overflow will occur in four situations, including: -
1/ The addition of large positive numbers.
2/ The addition of large negative numbers.
3/ The subtraction of a large positive number from a large negative numbers.
4/ The subtraction of a large negative number from a large positive number.

Overflow indicates that the result of an addition or subtraction requires more bits than are
available in the standard 8-bit register used to contain the result.

Fixed format representation: We now know how to represent signed integers: however,
we have not yet resolved the problem of magnitude. If we want to represent large
integers, we will need several bytes. In order to perform arithmetic operations efficiently,
it is necessary to use a fixed number of bytes, rather than a variable number. Therefore,
once the number of bytes is chosen, the maximum magnitude of the number that can be
represented is fixed.

Subtraction by use of complements.


 Complements are mainly used for representing negative numbers and subtraction.
 In performing binary subtraction or addition of negative number by use of binary
complements only one procedure, addition, is needed as one can subtract by adding its
complements.
 To subtract any number, positive or negative, substitute the required complement
for the numbers to be subtracted and then add.
If the result is an (n+1)-bit number, and the arithmetic is in Ones complement the (n+1) th
bit, a carry, is added to the right most bit of the result. This process is called an end-
around carry.
Two’s complement discard the (n+1) th bit. An n-bit number and the arithmetic is in

Organized By IT Department Page 11


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

Ones complement, to read the binary value calculate the ones complement of the
magnitude bits and place a minus sign front of it.
Two’s complement, to read the binary value calculate the two’s complement of the
magnitude bits and place a minus sign in front of it.

Example:
Perform the following in ones and two’s complements in 5-bits.
A. 12-6
B. 6-12
C. -12-6
A= 12 B=6, A=01100 B=00110
Ones complement of -A=10011 & -B=11001
Two’s complement of - A= 10100 & -B= 11010
Example C:
Is wrong this is because the occurrence of overflow. Arithmetic overflow is that part
of the result of an operation which is lost because of the resulting value exceeds the
capacity of the intended storage location.

* Arithmetic overflow occurs when the sign bits of A and B are the same but the sign

bit of the result is different.


Floating-Point Representation
In this representation decimal numbers are represented with a fixed length format. In
order not to waste bits, the representation will normalize all the numbers. For example,
0.000123 wastes three zeroes on the left before non -zero digits. These zeroes have no
meaning except to indicate the position of the Decimal point. Normalizing this number
result in .123x10-3 .123 is the normalized mantissa; -3 is the exponent. We have
normalized this by eliminating all the meaningless zeroes to the left of the first non-zero
digit and by adjusting the exponent.

Ex1: 22.1 is normalized as .221x102.


The general form of floating point representation is Mx10E where M is the mantissa,
and E is the exponent. It can be seen that a normalized number is characterized by a
mantissa less than 1 and greater than or equal to.1 all cases when the number is not zero.
To represent floating numbers in the computer system it should be normalized after
converting to binary number representation system.

Organized By IT Department Page 12


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

Ex2 111.01 is normalized as .11101x23.


The mantissa is 11101. The exponent is 3.
The general structure of floating point is

Sign Exponent Mantissa (significand)


In representing a number in floating point we use 1 bit for sing, some bits for exponent
and the remaining bit for mantissa.
In floating point representation the exponent is represented by a biased exponent
(Characteristics).

Biased exponent = true exponent + excess 2n-1, where n is the number of bits reserved for

the exponent.
Ex1. Represent –236.375 in floating point using 7 bit for exponent and 16 bit for
mantissa.
First we have to change to normalized binary
i. e 234 = 11100010
0.375= 0.011
234.375 = 11100010.011 = 0.11100010011x28
true exponent = 8
excess 2 n-1 = 2 7-1= 26= 64
Biased exponent = 8+26 8+64 = 72
= 100 1000 2
Therefore –234.375 is represented as
1 1001000 1110001001100000

Sign 7-bits 16 bits


Ex2. Represent 34.25 in floating point using 7 bit for exponent and 24 bits
for mantissa.
34.25 = 1000 10.0 12
The normalized form of 34.25 = .10001001x 26

True exponent = 62 n-1 = 2 7-1= 6+26 = 6+64=70

Organized By IT Department Page 13


INTRODUCTION TO INFORMATION TECHNOLOGY 2018

70 = 10001102

Therefore, 34.25 is represented as

0 1000110 100010010000…..0

Floating point overflows


If there are 1 bit for the sign, N bit for the exponent and M bit for the mantissa
(significant) we can represent numbers as shown below.
To represent a number in floating point:
 Represent the number in normalized binary form.
 Find the biased exponent
 Change the biased exponent to binary
 Write the sing, the exponent in the exponent part and the mantissa in the mantissa part
 If there are fewer digits in the exponent add zeros to the left and for mantissa add
zeros to the right.

Floating-point Arithmetic
To perform floating-point arithmetic:
 First correct the numbers to binary with the same exponent (the highest)
 Apply the operator on the mantissa and take one of the exponent
 Normalize the result
Ex1. Find 23.375+ 41.25 using 7-bit for exponent and 10 bit for mantissa.
23.375 = 10111.011 = 0.1011101x25 = 0.010111011x26

41.25 = 111001.01 = 0.11100101x26


23.37+41.25 = 0.01011101x26+0.1110010x26
= (0.010111011+0.11100101) x26
= 0.1010000101x26

Organized By IT Department Page 14

You might also like