0% found this document useful (0 votes)
46 views30 pages

Data Storage in Computer System: BITS Pilani

The document discusses data storage in computer systems using different number systems such as binary, octal, decimal, and hexadecimal. It explains the concept of positional number systems and how the value of a digit depends on its position. It then covers representation of integers, real numbers, and floating point numbers in these number systems. Conversions between different bases like binary to decimal, octal to hexadecimal etc. are demonstrated. Finally, it discusses fixed point and floating point number representations used in computers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views30 pages

Data Storage in Computer System: BITS Pilani

The document discusses data storage in computer systems using different number systems such as binary, octal, decimal, and hexadecimal. It explains the concept of positional number systems and how the value of a digit depends on its position. It then covers representation of integers, real numbers, and floating point numbers in these number systems. Conversions between different bases like binary to decimal, octal to hexadecimal etc. are demonstrated. Finally, it discusses fixed point and floating point number representations used in computers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

DATA STORAGE IN COMPUTER

SYSTEM
Sadhana Jha
BITS Pilani Computer Science and Information Systems Department
BITS, Pilani
Pilani Campus
 Four different number systems:

 Binary base 2

 Octal base 8

 Decimal  base 10

 Hexadecimal  base 16
 Positional number system:

 Value of a digit in a number depends upon it’s position in the number

 Example:

 742 : 7 * 102 + 4 * 101 + 2 * 100 Value of 7 is 700

 472: 4 * 102 + 7 * 101 + 2 * 100  Value of 7 is 70

 247: 2 * 102 + 4 * 101 + 7 * 100 Value of 7 is 7

 Value of a number depends on the following:

 The digits in the number

 Position of the digits in the number

 Base of the number system


 Base: Gives the upper limit on the maximum character a number system
can have
 Base 2  0 – 1 (2 characters)

 Base 8  0 – 7 (10 characters)

 Base 10  0 -9 (8 characters)

 Base 16  0 – 9, A, B, C, D, E, F (16 characters)

Question?
 Computer understand which number system ?
 Why do we need other number systems?
Binary Number system
 0, 1 are the only allowed character

 Steps to represent a decimal number N in binary:


 Divide N by 2 and store the quotient

 Repeat step 1, until the number cannot be divided further

 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

 Print all the value of X’.

Example - Convert 10.6875 to binary


(10)10 = (1010)2
(0.6875) 10 =
0.6875 * 2 = 1.375 -------- 1 = (1 0 1 0. 1 0 1 1)2
0.375 * 2 = 0.75 -------- 0
0.75 * 2 = 1.5 -------- 1
0.5 * 2 = 1.0 -------1
 Representation of floating point number into real numbers

 Binary number: X.Y

 X – Similar to the way integer values are obtained (Explained in


previous slides)

 Y

 Multiply each bit with the weight of its position, where weight of the
positions are: 2-1, 2-2, 2-3,.....

 Take the sum of the output

 E.g. 1 0 1 0 . 1 0 1 1

Integral part Fractional part


1010 . 1011

 Integral Part : (1 0 1 0)2 = 1 * 23 + 0 * 22 + 1 * 21 + 0 * 20 = 10


 Fractional part: (1 0 1 1)2

= 1 * 2-1 + 0 * 2-2 + 1 * 2-3 + 1 * 2-4

= 1/2 + 0 + 1/8 + 1/16

= 0.5 + 0 + 0.125 + 0.0625

= 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

d and n represents digits and their position in the number, respectively


 (A 1 C 2)16,

Digits (d) Position (n)


d0 = A = 10 n=3

d1 = 1 n=2
d2 = C n=1
d3 = 2 n=4

 Putting in above formula, 10×163 + 1×162 + 12×161 + 2 * 160 = (41410)10

 Conversion from decimal to Base r

 Use the repeated reminder/quotient method


 Conversion from Hexadecimal to decimal number

 (dn-1dn-2-3... d2d1d0)r = (dn-1×16n-1 + dn-2×16n-2 + ... + d1×161 + d0×160 )10

 E.g: (B 0 9 3)16

 d1 = B, d2 = 0, d3 = 9, d4 = 3

= 11×163 + 0×162 + 9×161 + 3 * 160

= (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

 (dn-1dn-2-3... d2d1d0)r = (dn-1×8n-1 + dn-2×8n-2 + ... + d1×81 + d0×80 )10

 E.g: (1073)16

 d1 = 1, d2 = 0, d3 = 7, d4 = 3

= 1×83 + 0×82 + 7×81 + 3 * 80

= (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

 Starting from the right-most bit (LSB), replace each group of 3


bits by the equivalent octal digit (add extra zeros to the left-most
bits, if necessary)
 (001110111)2 = (001)8 (110)8 (111)8 = (167)8

 (11101)2 = (011101)2 = (011)8 (101)8 = (35)8

only two bits One extra zero added


 Octal to Binary Conversion

 Method 1

 Octal to Decimal

 Decimal to Binary

 Method 2

 Convert each octal digit to a 3-digit binary number

 (167)8 = (001)2 (110)2 (111)2 = (001 110 111)2


 Binary to Hexadecimal Conversion

 Method 1

 Binary  Decimal  Hexadecimal

 Method 2

 Starting from the right-most bit (LSB), replace each group

of 4 bits by the equivalent octal digit (add extra zeros to


the left-most bits, if necessary)
 (111001110111)2 = (1110)16 (0111) 16 (0111) 16 = (E77) 16

 (11101)2 = (00011101)2 = (0001) 16 (1101) 16 = (1D) 16

only one bit three extra zeros added


 Hexadecimal to Binary Conversion

 Method 1

 Hexadecimal  Decimal  Binary

 Method 2

 Convert each octal digit to a 4-digit binary number

 (167)16 = (0001)2 (0110)2 (0111)2 = (000101100111)2


Fixed Point representation: Define a fixed point number type

simply by implicitly fixing the binary point to be at some


position of a numeral.

 Two parameters are required:

 width of the number representation (w)

 binary point position within the number (b)

 E.g., <8,3> representation of 11101101 will be 111.10101


 Floating Point Representation – IEEE 754 Standard

 Place of the decimal point is not fixed

 E.g. - 2.5 * 105 and +3.32 * 10-6


 Three pieces of information are required:

 Sign of the number (s)

 Significant value (m)

 Signed exponent of 10 (e)

 The data type float uses IEEE 32-bit single precision format and the data

type double uses IEEE 64-bit double precision format


 In single precision (32 bits):
 The MSB indicates the sign bit (s): 1 is -ve and 0 is +ve.
 The next 8 bits: Stores the value of the signed exponent (e)
 Remaining 23: Stores the significand also know as
mantissa (m).
 Value of a floating number IN 32 bits is

 e – 127: Excess 127 representation, meaning if the exponent


value is 5, it will be stored as 5 + 127 = 132 in the exponent
field
 If e is treated as an unsigned number

 The valid range of the exponents is 1 to 254, i.e.,

21 to 2254

 Values 00000000 and 111111111 are reserved to represent

special values

 If e is treated as an signed number

 The actual exponent is biased by 127 .i.e. the actual value of

the exponent is e − 127. This gives the range:

21 −127 to 2254 −127 = = 2 −126 to 2127.


Normalization: Representation of floating point numbers with
leading 1 bit
Excess 127: Subtraction of 127 from the exponent
Floating point representation of 0.5 in 32 bits =
0| 00000000 | 010000000……

Normalized representation of 0.5 in 3.2 bits =


1.0 * 2-1 = 0| 01111110 | 000000000……

exponent Mantissa

 1| 01010101 | 010100000……

exponent Mantissa

= (-1)-1 * 1.3125 * 2-42


= - 0.3125 * 2-42
 Why excess 127?

 Helps in natural ordering in the values stored in the exponent field

 Consider 2-126 and 2+126

 Case 1: In absence of Excess 127:

 -126 = 10000010

 +126 = 01111110

 While -126 is a smaller value the exponent field contains larger value
(10000010 > 01111110)

 Case 2: In presence of Excess 127:

 -126 is written as 1 (1 – 127 = 6)  00000001

 +126 is written as 253 (253 – 127 = 126)  11111101

 -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….

= (-1)0 * 0.5 * 2128 - 127

= 0.5 * 21 (subtracting excess 127 from the exponent)

= 0.25 * 2 * 21

= 0.25 * 22 = 0.25 * 2129 (excess 127 format)

= 0 | 10000001 | 0 1 0 0 0 0…. (ambiguity, different representations


for same number)

 This can be avoided if the number is normalized

 Example: 1.5 * 21 != 0.15 * 22


 Represent a real number with an integer and a fraction part in
FP

 Convert and normalize the integer part into binary

 Convert the fraction part using the technique explained earlier

 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

1. (105)10 + (0.625)10 = (01101001)2 + (0.101)2 = (01101001.101)2

2. Shift (01101001.101)2 by 6 digits to normalize the value

(105.625)10 = (1.101001101)2 * 26

s = 1 (indicating the final value is negative)

Exponent = 133 (represented in excess 127, i.e., 133- 127 = 6)

Mantissa = 101001101 (extended to 23 bits)


FP Representation  1| 10000101 | 101001101….
 Five groups of single precision data can be represented using

IEEE 754 standard of FP representation:


 Five groups of double precision data can be represented using

IEEE 754 standard of FP representation:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy