0114-notes - CPSC 121 Lecture 5 January 14, 2009 Menu...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CPSC 121 Lecture 5 January 14, 2009 Menu January 14, 2009 Topics: Representing Values (contd) Example: 7 Segment LED Display Reading: Today: Epp 1.5 Friday: Epp 1.3 Next week: Epp 2.1, 2.3 Reminders: On-line Quiz 4 deadline 9:00pm January 15 READ the WebCT Vista course announcements board WebCT Vista: http://www.vista.ubc.ca www: http://www.ugrad.cs.ubc.ca/~cs121/ We now consider how we do simple arithmetic (addition/subtraction) with fixed width binary representations. Integer Arithmetic: Addition Lets 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 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 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 1s complement of 179 77 115 01001101 2s 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 2s complement is zero. We represent a negative number by its 2s complement. We subtract m from n by adding n and -m. That is, n - m = n + (-m) 2s Complement Most modern digital computers use 2s complement binary arithmetic for integer addition/subtraction. By convention,Most modern digital computers use 2s complement binary arithmetic for integer addition/subtraction....
View Full Document

This note was uploaded on 01/09/2010 for the course CPSC 121 taught by Professor Belleville during the Spring '08 term at The University of British Columbia.

Page1 / 5

0114-notes - CPSC 121 Lecture 5 January 14, 2009 Menu...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online