Download presentation
Presentation is loading. Please wait.
Published byGavin Curtis Modified over 9 years ago
1
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 20, 2004 Lecture Number: 23
2
2 Announcements Exam 2 –Monday 10/25/2004 –Covers LANsChapter 4 The InternetChapter 17 HTTP ands HTMLChapter 18 Today’s Material –Chapter 6
3
3 Review LAN’s The Internet HTML and HTTP
4
4 Outline Numeric Processing
5
5 Digital Number Representations Integers –Infinite discrete subset of the number line –Represented with a limited range Decimal numbers (real numbers) –Infinite and continuous –Represented with limited range and limited precision
6
6 Integer Storage Integer values can be exactly represented base 10 conversionbase 2
7
7 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001
8
8 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 21 = 2 1 0000 0010
9
9 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 22 = 2 1 0000 0010 44 = 2 2 0000 0100
10
10 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 22 = 2 1 0000 0010 44 = 2 2 0000 0100 88 = 2 3 0000 1000
11
11 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 22 = 2 1 0000 0010 44 = 2 2 0000 0100 88 = 2 3 0000 1000 99 = 8 + 1 = 2 3 +2 0 0000 1001
12
12 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 22 = 2 1 0000 0010 44 = 2 2 0000 0100 88 = 2 3 0000 1000 99 = 8 + 1 = 2 3 +2 0 0000 1001 1010 = 8 + 2 = 2 3 + 2 1 0000 1010
13
13 Integer Storage Integer values can be exactly represented base 10 conversionbase 2 11 = 2 0 0000 0001 22 = 2 1 0000 0010 44 = 2 2 0000 0100 88 = 2 3 0000 1000 99 = 8 + 1 = 2 3 +2 0 0000 1001 1010 = 8 + 2 = 2 3 + 2 1 0000 1010 2727 = 16+8+2+1 = 2 4 +2 3 +2 1 +2 0 0001 1011 most significant bit least significant bit
14
14 Integer Storage Integers are typically 32 bits (word size) Number of unique items that can be represented with 32 bits One-half of the symbols –Represent positive numbers –Represent negative numbers –Sign bit distinguishes between + and - numbers 2 32 = 4,294,967,296
15
15 Integer Storage Positive numbers 0, 1, 2, …, 2 31 - 1 Negative numbers -2 31 + 1, -2 31 + 2, …, -2, -1, 0 Two representations of zero –Get rid of one of them –Gives us one more number –Add it to the negative numbers
16
16 Integer Storage Range of integer numbers -2 31, -2 31 + 1, …, -2, -1 0, 1, 2, …, 2 31 - 1 -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 –Frequently occurs during math operations
17
17 Integer Overflow 3 bits –Can represent 2 3 = 8 values –{ 0, 1, 2, 3, 4, 5, 6, 7 } 4 10 = 100 2 + 3 10 = 011 2 = 111 2 4 10 = 100 2 + 5 10 = 101 2 9 10 7 10 = 001 2 1 How do I add two binary numbers? overflow carry out
18
18 Negative Numbers The range of integer numbers is -2 31, -2 31 + 1, …, -2, -1 0, 1, 2, …, 2 31 - 1 -2,147,483,648 … 2,147,483,647 –How do we represent negative numbers? Could use one bit as a sign bit, but … –Two’s complement representation solves The problem of two zeros Mathematical operations giving incorrect results
19
19 Two’s Complement Numbers Two steps in determining a two’s complement representation of a number –Positive numbers are the same as the positive sign-magnitude representation –Negative numbers Invert the bits of the unsigned quantity Add 1 to the result
20
20 Two’s Complement Numbers –Negative numbers Invert the bits of the unsigned quantity Add 1 to the result Decimal number Binary magnitude Bit inverseAdd one Two’s complement representation -4 01001011 + 1 1011 1 0 1 0 1 11 1100 -7 01111000 1011 + 1 1001
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.