Data Storage in Computer
Data Storage in Computer
Data Storage in Computer
SYSTEM
Sadhana Jha
BITS Pilani Computer Science and Information Systems Department
BITS, Pilani
Pilani Campus
Computer system, being a digital system, understands only 0 and
1
0/1 denotes on/off
Before storing in memory, data is converted to simple numbers
that are easy for a computer to store
Each number is then reduced to a sequence of 0 and 1
Numbers can be unsigned or signed
Unsigned: 0∞
Are stored in memory as it is
E.g., 6 0 1 1 0, which is the binary representation of 6
Signed: -∞ +∞
0 +∞ is represented similar to the unsigned numbers
-1 -∞ requires different way of storage
Three ways to represent negative numbers:
Sign magnitude
1’s complement
2’s complement
Requirements to be met
0+0=0
0+1=1
1+0=1
0–0=0
1–0=1
1–1=0
0 – 1 = 0 1 borrow
Sign Extension
Increasing the number of bits of a binary number while
preserving the number's sign and value
• (73)10 = (1001001)2 = (01001001)2 after sign extension
0 1 1 0 (+6)
1 0 1 1 (-3)
discarded
32d requirement ?
+0 0 0 0 0
e.g: -6 : 1 1 1 1 – 0 1 1 0 = 1 0 0 1
2nd Method:
e.g: -6 : 0 1 1 0 1 0 0 1
Range of values using N bits is [- 2N-1 -1 , +2N-1 -1]
4. If there is no carry over, find the 1CT of the result and add –ve sign
before it
Consider 7 – 4:
1. 1CT (0 1 0 0) = 1 0 1 1
2. 0111
+ 1011
10010
3. 0010
+ 0001
0 0 1 1 +3
Consider 4 – 7
1. 1CT(7) = 1 0 0 0
2. 0100
+1000
1100
3. 1CT(1 1 0 0) = 0 0 1 1
-0 1CT(0000) 1111
2’s complement (2CT):
1st Method: Subtract the number from [2N-1 -1] and then add +1
e.g: -6 : 1 1 1 1 – 0 1 1 0 = 1 0 0 1 + 0 0 0 1 1 0 1 0
2nd Method:
e.g: -6 : 0 1 1 0 1 0 0 1 + 1 1 0 1 0
Range of values using N bits is [- 2N-1 , +2N-1 -1]
3. If there is a carry over discard it, the remaining bits gives the result
4. If there is no carry over, find the 2CT of the result and add –ve sign
before it
Consider 7 – 4:
1. 2CT (0 1 0 0) = 1 0 1 1 + 0 0 0 1 1 1 0 0
2. 0111
+ 1100
1 0 0 1 1 +3
Discard
Consider 4 – 7
1. 2CT(7) = 1 0 0 0 + 0 0 0 1 = 1 0 0 1
2. 0100
+1001
1101
3. 2CT(1 1 0 1) = 0 0 1 0 + 0 0 0 1 0 0 1 1
2CT(+8) = 1 0 0 0
2CT(-8) = 1CT(1 0 0 0) + 0 0 0 1
0 1 1 1 + 0 0 0 1 1 0 0 0 = 2CT(+8)
To avoid the ambiguity about whether (1 0 0 0)2 should be considered as
2CT of +8 or -8 consider the following addition
1 0 0 0 2CT of either +8 or -8
+ 0 1 1 1 2CT(+7)
1 1 1 1 2CT(-1) , X + 7 = -1 X = -8
2CT of X = -X ? prove.
1 0 1 0 (-6) 1 1 1 0 (-2)
1 0 0 1 (-7) 1 1 0 1 (-3)
1 0 0 1 1 (+3) 1 1 0 1 1 (-5)
Carry
Overflow
Observations:
When addition is performed on two numbers having same MSB
When C3 ≠ C4
Binary base 2
Octal base 8
Decimal base 10
Hexadecimal base 16
Positional number system:
Example:
Base 10 0 -9 (8 characters)
Question?
Computer understand which number system ?
Why do we need other number systems?
Binary Number system
0, 1 are the only allowed character
E.g, ( 10 )10 = ( 0 1 0 1 0 )2
2 10
2 5 0
2 2 1 = (0 1 0 1 0)2
2 1 0
0 1
Steps to convert binary to decimal number
In a n-bit binary number weight of the positions are:
2n-1, 2n-2, 2n-3,..... 21, 20
e.g1 : (0 1 0 1 0 1 1 0)2 =
(0*27 + 1*26 + 0*25 + 1*24 + 0*23 + 1*22 + 1*21 + 0*20)2
= (0 + 64 + 0 + 16 + 0 + 4 + 2 + 0)2
= (86)10
e.g2 : (1 0 1 0 1 0)2
= (1*25 + 0*24 + 1*23 + 0*22 + 1*21 + 0*20)2
= (32 + 0 + 8 + 0 + 2 + 0)2
= (42)10
Representation of real numbers using binary
Real numbers: X.Y
X – Similar to the way integers are represented (Explained in previous slides)
Y
Y * 2 = X’. Y’
Store X’ and Y = Y’
Repeat step 1 and 2, for the new fractional value obtained until X’.Y’ = 1.0
Y
Multiply each bit with the weight of its position, where weight of the
positions are: 2-1, 2-2, 2-3,.....
E.g. 1 0 1 0 . 1 0 1 1
= 0.6875
(1 0 1 0 . 1 0 1 1)2 = (10.6875)10
Conversion from Base r to decimal number
(dn-1dn-2... d2d1d0)r = (dn-1×rn-1 + dn-2×rn-2 + ... + d1×r1 + d0×r0 )10, Where
E.g: (B 0 9 3)16
d1 = B, d2 = 0, d3 = 9, d4 = 3
= (4243)10
16 261
Conversion from decimal to Hexadecimal 16 5
16
E.g: (261)10 = (105)16 16 1 0
0 1
Conversion from Octal to decimal number
E.g: (1073)16
d1 = 1, d2 = 0, d3 = 7, d4 = 3
= (571)10
8 261
Conversion from Decimal to Octal
8 32 5
E.g: (261)10 = (405)8
8 4 0
0 4
Binary to Octal Conversion
Method 1
Binary to Decimal
Decimal to Octal
Method 2
Method 1
Octal to Decimal
Decimal to Binary
Method 2
Method 1
Method 2
Method 1
Method 2
The data type float uses IEEE 32-bit single precision format and the data
21 to 2254
special values
exponent Mantissa
1| 01010101 | 010100000……
exponent Mantissa
-126 = 10000010
+126 = 01111110
While -126 is a smaller value the exponent field contains larger value
(10000010 > 01111110)
-126 is a smaller value and so is the value stored in the exponent (00000001 <
11111101)
Why normalization ?
0 | 10000000 | 1 0 0 0 0….
= 0.25 * 2 * 21
Add the two results and adjust them to produce a proper final
conversion
Example 1: 12.375
1. (12)10 + (0.375)10 = (1100)2 + (0.011)2 = (1100.011)2
2. Shift (1100.011)2 by 3 digits to normalize the value
(12.375)10 = (1.100011)2 * 23
s=0
Exponent = 130 (represented in excess 127)
Mantissa = 100011
FP Representation 0| 10000010 | 1000110000……
Example 2: -105.625
(105.625)10 = (1.101001101)2 * 26