cpsc 121 models of computation
play

CPSC 121: Models of Computation Instructor: Bob Woodham - PowerPoint PPT Presentation

CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2009/2010, Section 203 CPSC 121: Models of Computation Menu January 18, 2010 Topics:


  1. CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2009/2010, Section 203 CPSC 121: Models of Computation

  2. Menu January 18, 2010 Topics: Representing Values (cont’d) Pre-class reading: Today: Epp 1.5 Next: Epp 1.3 Handouts: Converting signed binary numbers to/from decimal Reminders: READ the WebCT Vista course announcements board Assignment 1 coming soon Lab 2 this week (pre-lab worth marks) www: http://www.ugrad.cs.ubc.ca/~cs121/ WebCT Vista: http://www.vista.ubc.ca CPSC 121: Models of Computation

  3. Characters Characters are encoded into an 8 bit byte. There are two standard encodings, ASCII and EBCDIC ASCII stands for American Standard Code for Information Interchange. ASCII is the most widely used character encoding EBCDIC stands for Extended Binary Coded Decimal Interchange Code. EBCDIC was widely used by IBM but not widely used elsewhere. It still persists today, mainly on IBM mainframes The International Standards Organization (ISO), has developed a 2 byte–per–character encoding, called Unicode, that includes, for example, cyrillic, Chinese and Japanese character sets. Unicode is the standard character encoding used in the Java programming language CPSC 121: Models of Computation

  4. Integer Arithmetic: Addition Let’s add two bytes, both in octal and in binary: octal binary 263 10110011 120 01010000 ----------------------- 403 100000011 Positional notation, in any base, facilitates addition. One must take “carry” into account. In octal, when two columns sum to 8 (or more) carry to the left occurs. In binary, when two columns sum to 2 (or more) carry to the left occurs CPSC 121: Models of Computation

  5. N=8: Overflow Occurs In the previous example, the sum requires 9 bits to specify. What if there only are the 8 bits in a byte to hold the result? One must be aware that in finite precision integer arithmetic, carry to the left of the leftmost bit is lost Thus, in 8 bit byte arithmetic, (with leading zeroes omitted): octal binary 263 10110011 120 01010000 ----------------------- 3 11 CPSC 121: Models of Computation

  6. Representing Negative Numbers Want -n to be the number which when added to n gives 0 Consider the byte 179 10 = 263 8 = 10110011 2 decimal octal binary 179 263 10110011 76 114 01001100 1’s complement of 179 77 115 01001101 2’s complement of 179 ------------------------------------------------- 256 400 100000000 sum of lines 1 and 3 In n bit arithmetic, the sum of an n bit binary number and its 2’s complement is zero. We represent a negative number by its 2’s complement. We subtract m from n by adding n and -m. That is, n - m = n + (-m) CPSC 121: Models of Computation

  7. 2’s Complement Most modern digital computers use 2’s complement binary arithmetic for integer addition/subtraction. By convention, in n bit 2’s complement arithmetic, if the leftmost bit is 1 the number will be considered negative. Otherwise, it will be considered non-negative. Thus, if integers are stored in n bits, the numbers range from − 2 n − 1 to 2 n − 1 − 1 NOTE: Integer multiplication/division is more complicated. In general, multiplication of two n bit numbers produces a 2n bit product. Overflow is a serious issue in integer multiplication CPSC 121: Models of Computation

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend