210 likes | 325 Views
CSE111: Great Ideas in Computer Science. Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu. Announcements. Recitations have started this week! You have this week and next to complete HW1. cell phones off (please). Agenda.
E N D
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu
Announcements • Recitations have started this week! • You have this week and next to complete HW1.
cell phones off (please)
Agenda • Review from last class • fixed-width representations • two’s complement • Today’s topics • two’s complement • Underlying hardware
Fixed-width encodings • Suppose we have a four-bit wide representation. • We then have 24 = 2*2*2*2 = 16 distinct bit patterns:
Overflow • Compute the following sums, in a four-bit wide base 2 representation: 5 + 1 = 6 8 + 8 = 16 10 + 12 = 22 101 1000 1010 + 001+ 1000+ 1100 110 0000 0110
How about negative and non-negative numbers? • How can we assign the bit strings from 0000 to 1111 to numbers, including negative numbers? • There are many ways to do this, but some ways are better than others. • Keep in mind, we only have the symbols ‘0’ and ‘1’ to use.
Desirable properties of our representation X – Y = X + (-Y) X + (-X) = 0 0 = - 0 - (-X) = X
How does it work? • Given representation for x, compute representation of –x as follows: • First compute the 1’s complement by inverting all the bits (change 0 to 1, and 1 to 0) • Then compute the 2’s complement by adding 1, and ignoring any overflow carry bit.
Examples • Compute the representation of -1: 0001 original representation 1110 one’s complement 1111 two’s complement • Representation of -1 is 1111.
Check: x + (–x) = 0 0001 + 1111 0000 • Remember, representation is 4 bits wide, and we discard any overflow carry bit.
Check other properties too!(done on board) X – Y = X + (-Y) X + (-X) = 0 0 = - 0 - (-X) = X
Gates • Basic building blocks of computers are gates… • and • or • not • …and wires to connect them to each other.
Gate images http://upload.wikimedia.org/wikipedia/commons/5/5d/Logic-gate-and-us.png http://upload.wikimedia.org/wikipedia/commons/c/c8/Logic-gate-or-us.png http://upload.wikimedia.org/wikipedia/commons/d/d0/Logic-gate-inv-us.png
4-bit one’s complement A A’ B B’ C C’ D D’
Flip-flophttp://commons.wikimedia.org/wiki/File:RS_Flip-flop_(NOR).svgFlip-flophttp://commons.wikimedia.org/wiki/File:RS_Flip-flop_(NOR).svg