Download presentation
Presentation is loading. Please wait.
Published byÏΓάϊος Βασιλείου Modified over 6 years ago
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 = 106 = Express the sum as an 8-bit integer. = Carry-out bit is thrown away. Conclusions = 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
: Signed -128 to -1 Unsigned 0 to 255 Signed 0 to 127
7
It’s a Matter of Interpretation
: Signed -128 to -1 +1 Unsigned 0 to 255 +1 Signed 0 to 127
8
It’s a Matter of Interpretation
: Signed -128 to -1 –1 Unsigned 0 to 255 –1 Signed 0 to 127
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 = What value is ? What value is ? What value is ? What value is ?
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.