Information Technology Reference
In-Depth Information
to obtain (1)(001110). If the carry bit is added to the least significant bit of the result,
we obtain (001111), that is, (
15), which is a correct result.
Table 4.1 shows a comparison between the 2's complement and the 1's comp-
lement in the representation of an 8-bit number, x.
þ
4.2. INTEGER ARITHMETIC
In this section, we introduce a number of techniques used to perform integer arith-
metic using the radix complement representation of numbers. Our discussion will
focus on the base “2” binary representation.
4.2.1. Two's Complement (2's) Representation
In order to represent a number in 2's complement, we perform the following two steps.
1. Perform the Boolean complement of each bit (including the sign bit);
2. Add 1 to the least signi fic ant bit (treating the number as an unsigned binary
integer), that is,
A ¼ A þ
1
Example
Consider the representation of (
22) using 2's complement.
2
22
¼
00010110
+
11101001 (1's complement)
þ
1
11101010 (
22)
4.2.2. Two's Complement Arithmetic
Addition
Addition of two n-bit numbers in 2's complement can be performed
using an n-bit adder. Any carry-out bit can be ignored without affecting the correct-
ness of the results, as long as the results of the addition is in the range
2 n 1
2 n 1
to
þ
1.
Example
Consider the addition of the two 2's complement numbers (
7) and
2
(
þ
4). This addition can be carried out as (
2
7)
þ
(
þ
4)
¼ 2
3, that is, 1001
þ
(0100)
¼
1101, a (
2
3) in 2's complement.
2 n 1
þ
2 n 1
1is
important because a result outside this range will lead to an overflow and hence a
wrong result. In simple terms, an overflow will occur if the result produced by a
The condition that the result should be in the range
to
Search WWH ::




Custom Search