1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 22, 2004 Lecture Number: 24.

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Advertisements

Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
Chapter 8 Representing Information Digitally.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: November 10, 2004 Lecture Number: 31.
Floating Point Numbers
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Standard positional representation of numbers:
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
Computer Science 210 Computer Organization Floating Point Representation.
School of Computer Science G51CSA 1 Computer Arithmetic.
Binary Representation and Computer Arithmetic
The Binary Number System
February 26, 2003MIPS floating-point arithmetic1 Question  Which of the following are represented by the hexadecimal number 0x ? —the integer.
Simple Data Type Representation and conversion of numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
IT253: Computer Organization
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Numeric Processing Chapter 6, Exploring the Digital Domain.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.
Data Representation in Computer Systems
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 20, 2004 Lecture Number: 23.
Round-off Errors and Computer Arithmetic. The arithmetic performed by a calculator or computer is different from the arithmetic in algebra and calculus.
CSC 221 Computer Organization and Assembly Language
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: November 08, 2004 Lecture Number: 30.
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Numbers in Computers.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Software Design and Development Storing Data Computing Science.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
William Stallings Computer Organization and Architecture 8th Edition
Fundamentals of Computer Science
William Stallings Computer Organization and Architecture 7th Edition
Chapter 6 Floating Point
Data Structures Mohammed Thajeel To the second year students
Number Representations
How to represent real numbers
ECEG-3202 Computer Architecture and Organization
COMS 361 Computer Organization
Chapter 8 Computer Arithmetic
COMS 161 Introduction to Computing
Number Representations
Presentation transcript:

1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 22, 2004 Lecture Number: 24

2 Announcements Exam 2 –Monday 10/25/2004 –Covers LANsChapter 4 The InternetChapter 17 HTTP ands HTMLChapter 18 Today’s Material –Chapter 6

3 Review Numeric Processing Integers –Magnitude representation –Sign-magnitude representation –Two’s complement numbers

4 Outline Numeric Processing –Real numbers

5 Magnitude Numbers Use straight decimal to binary conversion, where N 10 = a n * 2 n + a n-1 * 2 n-1 + … a 1 * a 0 * 2 0 The coefficients (a n, a n-1, … a 1, a 0 ) correspond to the binary representation = 1* * * * =

6 Magnitude Numbers Can represent 2 n numbers –n is the number of bits { 0, 1, 2, …, 2 n – 1 } n = 0, 2 n = 2 0 = 1, { 0 } n = 1, 2 n = 2 1 = 2, { 0, 1 } n = 2, 2 n = 2 2 = 4, { 0, 1, 2, 3 } n = 3, 2 n = 2 3 = 8, { 0, 1, 2, 3, 4, 5, 6, 7 } Main problem: –No representation for negative numbers

7 Sign-Magnitude Numbers Provides a representation for negative numbers –Most significant bit (MSB) is 0 for positive numbers 1 for negative numbers –One half of the numbers represent Positive numbers –The other half of the numbers represents Negative numbers

8 Sign-Magnitude Numbers The positive numbers for n bits { 0, 1, 2, …, ((2 n ) / 2) – 1 } { 0, 1, 2, …, 2 n-1 – 1 } n = 0, 2 n-1 - 1= = -1, {. } –Not even a positive number!!! –Can not represent any numbers with 0 bits!!! n = 1, 2 n-1 – 1 = 2 0 – 1 = 0, { 0 } –Can represent the sign bit with a single bit!!! n = 2, 2 n-1 – 1 = 2 1 – 1 = 1, { 0, 1 } –Two bits, one sign bit one magnitude bit, (2 values)

9 Sign-Magnitude Numbers –Positive numbers represented n = 2, 2 n-1 – 1 = 2 1 – 1 = 1, { 0, 1 } n = 3, 2 n-1 – 1 = 2 2 – 1 = 3, { 0, 1, 2, 3 } n = 4, 2 n-1 – 1 = 2 3 – 1 = 7, {0, 1, 2, 3, 4, 5, 6, 7}

10 Sign-Magnitude Numbers The negative numbers for n bits {-((2 n ) / 2) + 1, -((2 n ) / 2) + 2, … -1, 0 } {-2 n-1 + 1, -2 n-1 + 2, … -1, 0 } n = 0, -2 n = = 1 –Not even a negative number!!! –Can not represent any numbers with 0 bits!!! n = 1, -2 n = = 0, { 0 } –Can represent the sign bit with a single bit!!! n = 2, -2 n = = -1, { -1, 0 } –Two bits, one sign bit one magnitude bit, (2 values)

11 Sign-Magnitude Numbers –Negative numbers represented n = 2, -2 n = = -1, { -1, -0 } n = 3, -2 n = = -3, { -3, -2, -1, -0 } n =4,-2 n-1 +1= = -7, {-7,-6,-5,-4,-3,-2,-1,-0}

12 Sign-Magnitude Mathematical operations sometimes give an incorrect result 4 – 3 = = (-3)

13 Two’s Complement Numbers Two steps –Invert bits of the magnitude representation of the number –Add one (1) to the result Magnitude number: Magnitude representation: 0111 Bit inversion: 1000 Add one: in two’s complement is: 1001

14 Two’s Complement Mathematical operations give a correct result 4 – 3 = = (-3) Ignore the carry-out

15 Two’s Complement Mathematical operations give a correct result 3 – 4 = = (-4)

16 Two’s Complement Mathematical operations give a correct result -3 – 4 = = (-4) Ignore the carry-out

17 Two’s Complement Numbers Solves the two problems of sign- magnitude numbers –Two representations of zero problem –Mathematical operations Give the correct result Result is in two’s complement representation

18 Real Numbers Scientific Notation –Number times 10 to a power = * 10 3 Normalized scientific notation –Zero to the left of the decimal point = * 10 6 Advantageous to store real numbers in 32 bits (word size)

19 Real Numbers = 0 * * * * = = /2 1/4 1/8 1/16

20 Real Numbers = 0 * * – 8 10 = = 1 * – 4 10 = Decimal to binary conversion algorithm

21 Real Numbers 2 0 = = = = = = = = = – 0.5 = = 1 * = 1 * – 0.25 = = 1 * – = = 0.????? 2

22 Real (Decimal) Number Storage Real numbers are stored in floating point representation –A sign –An exponent –A mantissa (normalized decimal fraction) No digits to the left of the decimal First digit to the right of the decimal is nonzero

23 Real (Decimal) Number Storage Floating point number representation –32-bit s eeeeeeee fffffff ffffffffffffffff –s: sign bit –e: exponent bits [-126 … 127] –f: fractional part [23 bits + 1 implied bit]

24 Real (Decimal) Number Storage Numbers have limited precision –Most real numbers have an infinite decimal expansion

25 Real Number Storage Limited Range and Precision There are three categories of numbers left out when floating point representation is used –Numbers out of range because their absolute value is too large (similar to integer overflow) –Numbers out of range because their absolute value is too small (numbers too near zero to be stored given the precision available –Numbers whose binary representations require either an infinite number of binary digits or more binary digits than the bits available

26 Real Number Storage Limited Range and Precision Illustrated With one bit to the right of the decimal point, only the real number 0.5 can be represented.

27 Real Number Storage Limited Range and Precision Illustrated real numbers that can be represented with two bits 0.25, 0.5, 0.75 real numbers that can be represented with three bits 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, The holes correspond to all the unrepresented numbers: 0.126, 0.255, 0.3, …

28 Limited Range and Precision Some Consequences Limited range will invalidate certain calculations –If integers are involved, this can often be avoided by switching to real numbers –For real number calculations, this problem arises infrequently and in those cases can sometimes be handled by special methods –It is not a common occurrence in non- scientific work

29 Limited Range and Precision Some Consequences Limited precision for real numbers is very pervasive –Assume that most decimal calculations will, in fact, be in error! –Evaluate and use computer calculations with this in mind

30 Social Themes Risks in Numerical Computing Almost all computer calculations involve roundoff error (limited precision error) If not monitored and planned for carefully, such errors can lead to unexpected and catastrophic results –Arianne 5 Rocket Failure –Patriot Missile Failure during Gulf War

31 Software for Numerical Work Software Libraries Spreadsheets Mathematical Software –symbolic manipulation –data analysis –data visualization

32 CSC 101 Overview of Computer Science Lecture 15 03/02/2004 Numeric Processing

33 Integer Storage Integers are typically 32 bits (word size) Little-endian: intel –Most significant byte on the right Big-endian: SUN, SGI –Most significant byte on the left LSBMSB LSB

34 Integer Storage Problem occurs when a binary file is transferred between different endian machines Pow-Wow

35 Integer Storage Range of integer numbers –32 bits (4 bytes) per integer -2,147,483,648 … 2,147,483,647 integer overflow error –Trying to represent an integer that is larger than the most positive allowable integer or more negative than most negative integer Show Overflow

36 Binary to Decimal Conversion Recall positional notation –Position of the digit determines its values = 1* * * * * * * *2 0 = 1* *64 + 1*16 + 1*8 + 1*2 + 1*1 = =

37 Binary to Decimal Conversion Algorithm: Binary digits: … Base 2 powers: 2n2n 2 n … Multiply columns: 2n2n … Add values: 2 n + … = number 10

38 Decimal to Binary Conversion Algorithm: –Subtract the largest power of 2 that is less than or the same as the decimal number from the decimal number –Place a 1 in the 2 4 position Change to its binary representation Largest power of 2 less than is 4 since 2 4 ≤ 16 < 27 < 32 = – 16 = 11

39 Decimal to Binary Conversion Algorithm: –Repeat until the decimal value is ***1* 2 3 = 8 ≤ 11 < 16 = = *** = 2 ≤ 3 < 4 = – 2 = *1* ≤ 1 1 – 1 = *1111

40 Decimal to Binary Conversion Algorithm: –Put zeros where there are *’s –Can add leading zeros if you like =

41 Real Numbers Scientific Notation –Number times 10 to a power = * 10 3 Normalized scientific notation –Single digit to the left of the decimal point = * 10 5 Advantageous to store real numbers in 32 bits (word size)

42 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

43 Real (Decimal) Number Storage IEEE standard 754 –floating point number representation –32-bit s eeeeeeee fffffff ffffffffffffffff –s: (1) sign bit 0 means positive, 1 means negative

44 Real (Decimal) Number Storage s eeeeeeee fffffff ffffffffffffffff –e: (8) exponent bits [-126 … 127] A bias of 127 is added to the exponent Exponent of 0 is stored as 127, stored exponent of 200 means actual exponent is (200 – 127) = 73 Stored exponent of all zeros and ones are reserved for special numbers –f: (24) fractional part [23 bits + 1 implied bit] Since number to the left of the decimal point is not zero, its binary representation will have a leading one Saves a bit, a one is implied and does not need to be explicitly stored

45 Real (Decimal) Number Storage 32-bit floating point number has less precision that a 32-bit integer number Floating point number has 24-bits resolution seeeeeeee f f f f f f ff f f f Byte

46 Real (Decimal) Number Storage Can represent –A large range of floating point numbers –Numbers to greater precision By adding more bytes seeeeeeee f f f f f f ff f f f Byte

47 Real (Decimal) Number Storage Double precision floating point numbers –s: (1) sign bit –e: (11) exponent bits [-1023 … 1024] –f: (53) fractional part [52 bits + 1 implied bit] seeeeeeeeee f f f ff f f f Byte f f f f Byte

48 Real (Decimal) Number Storage Numbers have limited precision Compute 1

49 Real Number Storage Limited Range and Precision There are three categories of numbers left out when floating point representation is used –Numbers out of range because their absolute value is too large (similar to integer overflow) –Numbers out of range because their absolute value is too small (numbers too near zero to be stored given the precision available –Numbers whose binary representations require either an infinite number of binary digits or more binary digits than the bits available

50 Real Number Storage Limited Range and Precision Illustrated

51 Limited Range and Precision Some Consequences Limited range will invalidate certain calculations –If integers are involved, this can often be avoided by switching to real numbers –For real number calculations, this problem arises infrequently and in those cases can sometimes be handled by special methods –It is not a common occurrence in non- scientific work

52 Limited Range and Precision Some Consequences Limited precision for real numbers is very pervasive –Assume that most decimal calculations will, in fact, be in error! –Evaluate and use computer calculations with this in mind

53 Social Themes Risks in Numerical Computing Almost all computer calculations involve roundoff error (limited precision error) If not monitored and planned for carefully, such errors can lead to unexpected and catastrophic results –Arianne 5 Rocket Failure –Patriot Missile Failure during Gulf War

54 Software for Numerical Work Software Libraries Spreadsheets Mathematical Software –symbolic manipulation –data analysis –data visualization

55 CSC 101 Overview of Computer Science Lecture 16 03/02/2004 Numeric Processing

56 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

57 Real (Decimal) Number Storage IEEE standard 754 –floating point number representation –32-bit s eeeeeeee fffffff ffffffffffffffff –s: (1) sign bit 0 means positive, 1 means negative

58 Real (Decimal) Number Storage s eeeeeeee fffffff ffffffffffffffff –e: (8) exponent bits [-126 … 127] A bias of 127 is added to the exponent Exponent of 0 is stored as 127, stored exponent of 200 means actual exponent is (200 – 127) = 73 Stored exponent of all zeros and ones are reserved for special numbers –f: (24) fractional part [23 bits + 1 implied bit] Since number to the left of the decimal point is not zero, its binary representation will have a leading one Saves a bit, a one is implied and does not need to be explicitly stored

59 Real (Decimal) Number Storage 32-bit floating point number has less precision that a 32-bit integer number Floating point number has 24-bits resolution seeeeeeee f f f f f f ff f f f Byte

60 Real (Decimal) Number Storage Can represent –A large range of floating point numbers –Numbers to greater precision By adding more bytes seeeeeeee f f f f f f ff f f f Byte

61 Real (Decimal) Number Storage Double precision floating point numbers –s: (1) sign bit –e: (11) exponent bits [-1023 … 1024] –f: (53) fractional part [52 bits + 1 implied bit] seeeeeeeeee f f f ff f f f Byte f f f f Byte

62 Real (Decimal) Number Storage Numbers have limited precision Compute 1

63 Real Number Storage Limited Range and Precision There are three categories of numbers left out when floating point representation is used –Numbers out of range because their absolute value is too large (similar to integer overflow) –Numbers out of range because their absolute value is too small (numbers too near zero to be stored given the precision available –Numbers whose binary representations require either an infinite number of binary digits or more binary digits than the bits available

64 Real Number Storage Limited Range and Precision Illustrated

65 Limited Range and Precision Some Consequences Limited range will invalidate certain calculations –If integers are involved, this can often be avoided by switching to real numbers –For real number calculations, this problem arises infrequently and in those cases can sometimes be handled by special methods –It is not a common occurrence in non- scientific work

66 Limited Range and Precision Some Consequences Limited precision for real numbers is very pervasive –Assume that most decimal calculations will, in fact, be in error! –Evaluate and use computer calculations with this in mind

67 Social Themes Risks in Numerical Computing Almost all computer calculations involve roundoff error (limited precision error) If not monitored and planned for carefully, such errors can lead to unexpected and catastrophic results –Arianne 5 Rocket Failure –Patriot Missile Failure during Gulf War

68 Software for Numerical Work Software Libraries Spreadsheets Mathematical Software –symbolic manipulation –data analysis –data visualization