## 4.3 INTEGERS

In the case of integer numbers, the addition and subtraction algorithms depend on the particular representation. Three nonredundant representation methods are considered in what follows: *B*'s complement, sign-magnitude, and excess-*E* (Chapter 3).

### 4.3.1 *B*'s Complement Addition

Given two *n*-digit *B*'s complement integers *x* and *y*, and an initial carry *c*_{in} equal to 0 or 1, then *z* = *x* + *y* + *c*_{in} is an (*n* + 1)-digit *B*'s complement integer. Assume that *x* and *y* are represented with *n*+1 digits. Then the natural numbers associated with *x*, *y*, and *z* are *R*(*x*) = *x* mod *B*^{n+1}, *R*(*y*) = *y* mod *B*^{n+1}, and *R*(*z*) = *z* mod *B*^{n+1} (Definition 3.4), so that

Thus a straightforward addition algorithm consists in representing *x* and *y* with *n*+1 digits and adding the corresponding natural numbers, as well as the initial carry, modulo *B*^{n+1} (that means without taking into account the output carry). In order to represent *x* and *y* with one additional digit, Comment 3.2 is taken into account. As before, the procedure natural_addition computes the sum of two natural numbers.

**Algorithm 4.18 B's Complement Addition**

ifx(n-1)<B/2thenx(n):=0;elsex(n):=B-1;end if;ify(n-1)<B/2theny(n):=0;elsey(n):=B-1;end if; natural_addition(n+1, c_in, x, y, not_used, z);

**Example 4.1** Assume that *B* = 10, *n* = 4, *c*_{in} = 0, *x* = −2345, and *y* = −3674.. Both *x* and *y* are negative so that they are represented by *R*(*x*) = − 2345 + 10

Get *Synthesis of Arithmetic Circuits: FPGA, ASIC and Embedded Systems* now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.