4.2 SUBTRACTION OF NATURAL NUMBERS
The following (pencil and paper) algorithm computes the n-digit representation of z = x − y − bin where bin is an initial borrow equal to 0 or 1; if z is negative—that means that z is not a natural number—the output borrow q(n) is equal to 1.
Algorithm 4.17 Subtraction
q(0):=b_in; for i in 0..n-1 loop if x(i)-y(i)-q(i)<0 then q(i+1):=1; else q(i+1):=0; end if; r(i):=(x(i)-y(i)-q(i)) mod B; end loop; negative:=q(n);
Another method consists in treating the subtraction of natural numbers as a particular case of the subtraction of integers (next section).
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.