Conversion Carry and Overflow Converting binary numbers to
Conversion, Carry and Overflow Converting binary numbers to: § Hex – straightforward; read class notes and slides § Unsigned (decimal) • don’t interpret as 2’s complement • Interpret as simple binary number § Signed (decimal) • Possible values are 0, 1, …, 2 n -1 • Interpret as 2’s complement representation • Possible values are -2 n-1, …, 0, … 2 n-1 -1 12 -Sep-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 3 -6 -carryoverflow 1
Conversion, Carry and Overflow § Carry • Note: When computer (blindly) performs addition, will a 1 bit be carried from the most significant bit (msb) position? Yes Carry § Overflow • Given the interpretation to be used (i. e. (1) unsigned binary/hex, or (2) signed binary (2’s compl. ) ), – Does the answer make sense? No Overflow – i. e. Did our fixed word length cause a problem? Yes Overflow (Related to Carry question, but not necessarily same) 12 -Sep-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 3 -6 -carryoverflow 2
More re Does Answer Make Sense? § Example: Addition A+B • If unsigned rep: Was there a carry from msb? • If 2’s complement rep: – Pos. + Pos. = Pos. OK – Neg. + Neg. = Neg. OK – Neg. + Pos. Or one of A, B is 0 Always OK – Neg. + Neg. = Pos. Overflow – Pos. + Pos. = Neg. Overflow § Remember: for 2’s complement rep, leftmost bit signals the sign of number (just as it did for signed magnitude rep) 12 -Sep-01 94. 201 - Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept. 2001 94201. lecture 3 -6 -carryoverflow 3
- Slides: 3