Professional Documents
Culture Documents
High Performance Computing: Matthew Jacob Indian Institute of Science
High Performance Computing: Matthew Jacob Indian Institute of Science
Lecture 2
Matthew Jacob
Indian Institute of Science
How is Data Represented?
Character data: ASCII code
Integer data
2
Integer Data
Whole numbers, i.e., numbers without fractional
part
In computer systems, you usually find support for
both “signed integers” and “unsigned integers”
e.g., C programming
int x; Can take +ve or -ve whole number values
unsigned int y; Can take on +ve whole number values
3
Representing Signed Integer Data
Sign-magnitude representation
Sign bit least significant bit
(lsb)
x x
n1 n 2
... x2 x1 xo
represents the value
n 2
xn1 i
(1) xi 2
i 0
Example: In 8 bits
13 is represented as 00001101
-13 is represented as 10001101
4
Alternative: 2s Complement Representation
The n bit quantity least significant bit
x x
n 1 n2
... x0
represents the signed integer value
n2
n 1 i
xn 1 2 xi 2
i 0
13 is represented as 00001101
-13 is represented as 11110011
5
Example: Signed integer
16bit 2s complement value 0xED7E
6
Which Representation is Better?
Considerations
Speed of arithmetic (addition, multiplication)
Speed of comparison
Range of values that can be represented
The 2s complement representation is widely
used
7
How is Data Represented?
Character data: ASCII code
Signed Integer data: 2s complement
Real data
8
Real data
Real numbers: points on the infinitely long
real number line
There are an infinitely many points between any
two points on the real number line
9
Real Data: Floating Point Representation
IEEE Floating Point Standard (IEEE 754)
32 bit value with 3 components ( s, e, f )
1. s (1 bit sign)
2. e (8 bit exponent)
3. f (23 bit fraction)
represents the value
s e 127
(1) 1. f 2
10
Example: IEEE Single Float
In 32 bits,
0 01111110 0000000000000000000000
11
0 0000
Example: IEEE Single Float. 1 0001
2 0010
32bit IEEE single float 0xBDCCCCCC 3 0011
3
B 1011
2 0.110011001100110011001100 C 1100
3 3 3 4 3 20 D 1101
2 ( 2 ... 2 ) E 1110
4 4 4
Answer: -0.1 decimal 3 1
F 1111
32 (1 2 4 )
12
More on IEEE Floating Point
Why is the exponent represented in this way?
(excess-127 representation for signed
integers)
Normalized representation
Special forms
Denormalized values (exp = 0; f = non-zero)
Zero (exp = 0; f = 0)
Infinity (exp = 255; f = 0)
NaN (exp = 255; f = non-zero)
13
How is Data Represented?
Character data: ASCII code
Signed Integer data: 2s complement
Real data: IEEE floating point
14