1 / 12

Number Systems and Circuits for Addition – Negative Integers

Number Systems and Circuits for Addition – Negative Integers. Lecture 7 Section 1.5 Mon, Jan 29, 2007. Addition of Fixed-Length Integers. Represent 150 and 106 as 8-bit integers. 150 = 10010110 . 106 = 01101010 . Express the sum as an 8-bit integer. 10010110 + 01101010 = 00000000 .

issac
Download Presentation

Number Systems and Circuits for Addition – Negative Integers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Number Systems and Circuits for Addition – Negative Integers Lecture 7 Section 1.5 Mon, Jan 29, 2007

  2. Addition of Fixed-Length Integers • Represent 150 and 106 as 8-bit integers. • 150 = 10010110. • 106 = 01101010. • Express the sum as an 8-bit integer. • 10010110 + 01101010 = 00000000. • Carry-out bit is thrown away. • Conclusions • 150 + 106 = 0. • 150 = –106.

  3. Example: UnsignedInt.cpp

  4. Two’s Complement • For binary numbers of fixed length n, the two’s complement of a is 2n – a • If a > 0, then –a is stored as the two’s complement of a. • The two’s complement of the two’s complement of a is a.

  5. Finding the Two’s Complement • To find the two’s complement of an n-bit binary number: • Reverse each bit, including leading zeros. • Add 1 to the result. • Reversing each bit is equivalent to subtracting from 111…1 = 2n – 1.

  6. It’s a Matter of Interpretation 11111111 : 10000001 10000000 01111111 : 00000001 00000000 Signed -128to-1 Unsigned 0to255 Signed 0to127

  7. It’s a Matter of Interpretation 11111111 : 10000001 10000000 01111111 : 00000001 00000000 Signed -128to-1 Unsigned 0to255 +1 +1 Signed 0to127

  8. It’s a Matter of Interpretation 11111111 : 10000001 10000000 01111111 : 00000001 00000000 Signed -128to-1 Unsigned 0to255 –1 –1 Signed 0to127

  9. Signed Integers • Let P = {0, …, 127} • Let N = {–128, …, –1} • High-order bit • Members of P have high-order bit = 0. • Members of N have high-order bit = 1. • Signed vs. unsigned • If nP, then signed(n) = unsigned(n). • If nN, then signed(n) = unsigned(n) – 256.

  10. Some Special Values • 0 = 00000000 • 127 = 01111111 • –128 = 10000000 • – 1 = 11111111 • What value is 00000001? • What value is 10000001? • What value is 11111110? • What value is 01111110?

  11. 2-Byte vs. 4-Byte Integers • Assign a short to an int. • Exactly what bits are copied to what locations? • The sign bit must be extended. short s = -1; int i = s;

  12. Example: ShortVsInt.cpp

More Related