Lectures9-10-11-12 - 211 Computer Architecture Spring 2017 Instructor Prof Santosh Nagarakatte Topics n C programming conclusion n Data Representation l

# Lectures9-10-11-12 - 211 Computer Architecture Spring 2017...

• Homework Help
• 57

This preview shows page 1 - 12 out of 57 pages.

Instructor: Prof. Santosh Nagarakatte Topics: n C programming conclusion n Data Representation l Reading: Chapter 2.1, 2.2, 2.3, 2.4, 2.5 211: Computer Architecture Spring 2017 2 Sign extension Signed integer 4-bit representation 8-bit representation 16-bit representation +1 0001 00000001 0000000000000001 -1 1111 11111111 1111111111111111 Rutgers University Santosh Nagarakatte 4 Floating point Integers typically written in ordinary decimal form n E.g., 1, 10, 100, 1000, 10000, 12456897, etc. But, can also be written in scientific notation n E.g., 1x10 4 , 1.2456897x10 7 What about binary numbers? n Works the same way n 0b100 = 0b1x2 2 Scientific notation gives a natural way for thinking about floating point numbers n 0.25 = 2.5x10 -1 = 0b1x2 -2 How to represent in computers? Why not use fixed point numbers? Rutgers University Santosh Nagarakatte 5 IEEE floating point standard Most computers follow IEEE 754 standard Single precision (32 bits) Double precision (64 bits) Extended precision (80 bits) S Fraction Exponent Rutgers University Santosh Nagarakatte 6 Numerical Values Three different cases: n Normalized values l exponent field 0 and exponent field 2 k -1 (all 1’s) l exponent = binary value – Bias » Bias = 2 k-1 -1 (e.g., 127 for float) l Value of the number = 1.(mantissa field) l Ex: (sign: 0, exp: 1, mantissa: 1) would give 0b1.1x2 -126 n Denormalized values l exponent field = 0 l exponent = 1 – Bias (e.g., -126 for float) l Value of the number = mantissa field (no leading 1) l Ex: (sign: 0, exp: 0, mantissa: 10) would give 0b10x2 -126 n Special values: represent + , - , and NaN Rutgers University Santosh Nagarakatte 7 Decimal to IEEE Floating Point 5.625 In binary 101.101 à 1.01101 x 2 2 Exponent field has value 2 n add 127 to get 129 Exponent is 10000001 Mantissa is 01101 Sign bit is 0 0 10000001 0110100000000000000000 Rutgers University Santosh Nagarakatte 8 Floating point in C 32 bits single precision (type float) n 1 bit for sign, 8 bits for exponent, 23 bits for mantissa l Sign bit: 1 = negative numbers, 0 = positive numbers l Exponent is power of 2 n Have 2 zero’s n Range is approximately -10 38 to 10 38 64 bits double precision (type double) n 1 bit for sign, 11 bits for exponent, 52 bits for mantissa n Majority of new bits for mantissa è higher precision n Range is -10 308 to +10 308 9 Rutgers University Santosh Nagarakatte 10 Floating Point Operations No exact representation for a floating point Mantissa is only 23 bits in 32 bit representation Least significant bits may be dropped Floating point operations are not associative (3.14 + 1e10) – 1e10 != 3.14 + (1e10 – 1e10). Why? Rutgers University Santosh Nagarakatte 11 iClicker Pop Quiz 1  • • • 