Data representation

advertisement
Data representation
In our familiar number system we have 10 symbols (0 to 9) to represent a
number. We call it decimal system or 10 base system. The place value of a
digit in this system is a multiple of 10x . For any other base value b, place
value of a digit is bx.
To process data in a computer, we need to represent them in the registers
of the processor. A register consists of several circuits.
Can we represent 10 symbols using an electric circuit? Obviously no. We
can symbolize an electric circuit into two states such as
(a) contains current
(b) no current
Similarly for a magnetic media such as a disk we may consider two states
(a) magnetized clockwise
(b) magnetized counterclockwise
We may think these two states as two symbols (say one is 0 and the other
is 1) to represent a number. Thus we have only two digits to represent a
number in the computer processor, in the memory or in the data storage
devices. Each individual circuit represents a digit and we term it as a bit (it
is an abbreviation from binary digit). Thus, at circuit level, we can
represent a number in the computer in binary form.
As you all know, the largest number for a given number of digits can be
obtained by filling out each position with the largest symbol. Such as
in decimal system, largest number with 3 digits = 999
similarly
in binary, largest number with 3 digits = 111
(999)10
(111)2
9 X 100 = 9
9 X 101 = 90
9 X 102 = 900
999
(999)10 = 103 - 1
1 X 20 =
1 X 21 =
1 X 22 =
(111)2 = 23 - 1
1
2
4
7
in
decimal
Now, it is understood that the more number of circuits we engage to
represent a number, the bigger number we can store. Also, the leftmost bit
is reserved for sign. 8 bits (i.e. 8 circuits) make a unit of memory which is
called a byte. If we employ 2 bytes (16 bits) for a number then, we will
have 15 bits for digits and the largest number that can be stored will be 2 151 = 32768. For 8 byte scheme 231 –1 = 2147483648
We have already seen above how to convert binary number to its decimal
equivalent. We would like to briefly see how we can convert any 10 base
number to binary number.
2 5208
2 2604 - 0
2 1302 - 0
2 651 - 0
2 325 - 1
2 162 - 1
2 81 - 0
2 40 - 1
2 20 - 0
2 10 - 0
2 5-0
2 2-1
1-0
Thus (5208)10 = (1010001011000)2
check
(1010001011000)2
1 X 23 =
8
1 X 24 =
16
1 X 26 =
64
1 X 210 = 1024
164X 212 = 4096
64
5208
in decimal
Thus we can represent any integer number in binary, if sufficient bits are
used.
What happens with non-integer (i.e. floating point) numbers?
(0.5)10 = ? in binary
0.5
x2
1.0
(0.5)10 = (0.1)2
Check :
(0.1)2 = 1 x 2-1 = (0.5)10
(0.1)10 = ? in binary
0.1
x2
0.2
x2
0.4
x2
0.8
x2
1.6
x2
1.2
x2
0.4
x2
0.8
x2
1.6
x2
1.2
x2
0.4
(0.1)10 = (0.00011001100110011..........)2 =(0.00011)2
It is clear that it is never possible to represent (0.1)10
exactly in binary and hence in the computer. However,
we can increase the accuracy by using more bits for
floating point numbers than that for integer numbers.
Also, the scheme for integers and floating point
numbers are different.
Data representation scheme for integer
0 1 2 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Sign bit
Data representation scheme for floating point numbers
A floating point number is first converted to its equivalent in exponential
form with the decimal point to the leftmost significant digit. such as
Exponent
57.234 = 0.57234 x 102
Mantissa
0 1 2 3 . . . . . . . .7. 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7 bit
for exponent
56 bit for mantissa
Sign bit
Character representation
Besides numbers we have to represent / store character and other symbols
in the computer. Usually they are coded in 8 bit words.
If we use 8 bits, we can store numbers ranging from
(00000000)2 --> decimal equivalent 0
(11111111)2 --> decimal equivalent --> 28-1= 255
So 256 symbols may be coded.
From the above discussion it should be understood that different types of
data are stored using different scheme. So before we store any data, we
have to specify the type of the data.
0
1
2
.
.
9
10
11
.
.
99
100
101
.
.
999
0
1
10
11
.
.
100
101
.
.
111
1000
.
1111
10000
Download