CS 160 Lecture 4 Martin van Bommel
Overflow In 16-bit two’s complement, what happens if we add = -32,768 So how do we store numbers > 32,767?
Large and Small Numbers On 9-digit calculator, = 1.0 E 9 In binary, = 1.0 x 2^8 Small numbers, = = 1.0 x 2^(-1)
Real Numbers in Binary x 2^4 = = = 13.5 In 16-bit word, sign mantissa exponent
8-bit Floating Point Binary? SMMMSXXX S-sign M-mantissa X-exp Largest number = x 2^111 = x 2^7 = 111 x 2^4 = 7 x 16 = 112 Larger? Use more bits, but still limit
8-bit Floating Point Addition = 1010 = x 2^4 = x 2^0100 => = 0001 = x 2^1 = x 2^0001 => add - align bits ( ) x 2^ x 2^100 => round-off error - add more bits, but limited
Precision and Overflow Precision - number of significant digits Single precision floating point (32-bits) has 24-bit mantissa = 6-7 decimal digits If too precise, digits lost = Overflow - number too big or too small Fatal error - invalid result (32, = -1)
Octal and Hexadecimal Octal - Base 8 - digits 0, 1, 2, 3, 4, 5, 6, 7 Hex - Base 16 - digits 0 - 9, A, B, C, D, E, F easy to convert from binary, = = 9D1 16