COMS 161 Introduction to Computing Title: Numeric Processing Date: November 03, 2004 Lecture Number: 28
Announcements Research paper proposal 2 due November 8, 2004
Review Integers Big-endian Little-endian Overflow
Outline Real numbers Representation Limitations
Two’s complement 32 bit signed numbers: maxint minint 0000 0000 0000 0000 0000 0000 0000 00002 = 010 0000 0000 0000 0000 0000 0000 0000 00012 = + 110 0000 0000 0000 0000 0000 0000 0000 00102 = + 210 ... 0111 1111 1111 1111 1111 1111 1111 11102 = + 2,147,483,64610 0111 1111 1111 1111 1111 1111 1111 11112 = + 2,147,483,64710 1000 0000 0000 0000 0000 0000 0000 00002 = – 2,147,483,64810 1000 0000 0000 0000 0000 0000 0000 00012 = – 2,147,483,64710 1000 0000 0000 0000 0000 0000 0000 00102 = – 2,147,483,64610 ... 1111 1111 1111 1111 1111 1111 1111 11012 = – 310 1111 1111 1111 1111 1111 1111 1111 11102 = – 210 1111 1111 1111 1111 1111 1111 1111 11112 = – 110 maxint minint
Real Numbers Scientific Notation Normalized scientific notation Number times 10 to a power 123456.0 = 123.456 * 103 Normalized scientific notation Zero to the left of the decimal point 123456.0 = 0.123456 * 106 Advantageous to store real numbers in 32 bits (word size)
Real Numbers 0.1012 = 0 * 20 + 1 * 2-1 + 0 * 2-2 + 1 * 2-3 22 21 20 2 -1 2 -2 2 -3 2 -4 4 2 1 1/2 1/4 1/8 1/16 4 2 1 0.5 0.25 0.125 0.0625 0.1012 = 0 * 20 + 1 * 2-1 + 0 * 2-2 + 1 * 2-3 0.1012 = 0.5 + 0.125 = 0.62510
Real Numbers Decimal to binary conversion algorithm 24 23 22 21 20 16 8 4 2 1 1210 = 0 * 24 + 1 * 23 1210 – 810 = 410 2 1 1 410 = 1 * 22 410 – 410 = 010
Real Numbers 0.87510 = 0.?????2 20 = 1 2 -1 = 0.5 1 0.87510 = 1 * 2 -1 2 -2 = 0.25 0.87510 – 0.5 = 0.37510 2 -3 = 0.125 2 -4 = 0.0625 0.37510 = 1 * 2 -2 1 2 -5 = 0.03125 0.37510 – 0.25 = 0.12510 2 -6 = 0.015625 0.12510 = 1 * 2 -3 1 2 -7 = 0.0078125 0.12510 – 0.125 = 010 2 -8 = 0.00390625 0. 2
Real (Decimal) Number Storage Real numbers are stored in floating point representation IEEE Standard 754 Allows using data on different machines A sign An exponent A mantissa also called a significand (normalized decimal fraction) Single digit to the left of the decimal point