Data representation Methodddd (2)
Data representation Methodddd (2)
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.
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;
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
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
10 16 Go from 10 …….2…….16
8 16 Go from 8 …….2…….16
16 8 Go from 16 …….2…….8
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
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
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.
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”.
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.
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
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
70 = 10001102
0 1000110 100010010000…..0
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