Download presentation
Presentation is loading. Please wait.
Published byHubert Bradley Modified over 8 years ago
1
CS 160 Lecture 4 Martin van Bommel
2
Overflow In 16-bit two’s complement, what happens if we add 0111111111111111 + 0000000000000001 1000000000000000 = -32,768 So how do we store numbers > 32,767?
3
Large and Small Numbers On 9-digit calculator, 999999999 + 1 = 1.0 E 9 In binary, 11111111 + 1 = 1.0 x 2^8 Small numbers, 0.5 10 = 0.1 2 = 1.0 x 2^(-1)
4
Real Numbers in Binary 0.11011 x 2^4 = 1101.1 = 8 + 4 + 1 + 0.5 = 13.5 In 16-bit word, 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 sign mantissa exponent
5
8-bit Floating Point Binary? SMMMSXXX S-sign M-mantissa X-exp Largest number 01110111 = 0.111 x 2^111 = 0.111 x 2^7 = 111 x 2^4 = 7 x 16 = 112 Larger? Use more bits, but still limit
6
8-bit Floating Point Addition 10 10 = 1010 = 0.101 x 2^4 = 0.101 x 2^0100 => 0 101 0 100 1 1 = 0001 = 0.1000 x 2^1 = 0.100 x 2^0001 => 0 100 0 001 add - align bits (0.1010 + 0.0001) x 2^4 0.1011 x 2^100 => 0 101 0 100 round-off error - add more bits, but limited
7
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 0.1 10 = 0.000110011001100110011... Overflow - number too big or too small Fatal error - invalid result (32,767 + 1 = -1)
8
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, 100 111 010 001 2 = 4721 8 1001 1101 0001 2 = 9D1 16
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.