4
$\begingroup$

How do I do in general addition/subtraction with n's complement?

With binary numbers its straightforward, convert the number you want to subtract to 1's or 2's complement then add the numbers. Handle overflow

But with n's complement, I'm quite lost. How do I do it? I believe convert the number to subtract to 10s complement then add

eg.

  1234(base10)  - 1122(base10) --------------   1234(base10) + 9988(10s) --------------  11222(base??) 

I belive I did wrong? As 1234-1122=112?

3 Answers 3

5

To convert a negative number into ten's complement, add it to (i.e. subtract its absolute value from) $10^n$, where $n$ is the number of digits you're working with. For example, for $n = 4$,

$-1122 \equiv 10000 - 1122 = 8878 \mod 10000.$

An easy way to do the conversion is to first convert to nines' complement and add one:

$-1122 \equiv (9999 - 1122) + 1 = 8877 +1 = 8878 \mod 10000.$

You can then calculate

$1234 - 1122 \equiv 1234 + 8878 = 10112 \equiv 112 \mod 10000.$

  • 0
    thank you for responding - however that is not what I meant, see this http://gato-docs.its.txstate.edu/slac/Subject/Math/Discrete/Radix-and-Reduced-Subtraction/Radix%20and%20Reduced%20Subtraction.pdf for explanation of my previous comment. No need to respond to this comment other than maybe update your answer...2017-09-19
2

I just ran across these two short papers which give a pretty good explanation of things:

Radix and Reduced Radix Complementation

Radix and Reduced Subtraction

  • 0
    the second link ('..Subtraction') is perfect.2017-09-18
0

For a general radix r's complement in base r, and supposing we care about m digits (this is important, as the idea is to ignore the last carry), then the r's complement ($N*$) of the number N is given by

$N* = r^m - N \mod r^m$

The r-1 complement is $N** n= r^m - 1 - N$. In fact, to go more general, if we care about m digits and n decimal digits, then

$N* = r^m - N$ and $N** = r^m - r^{-n} - N \quad\quad(\mod r^m$)

So here, I would convert to 9's complement and add one, then carry out the addition paying attention to only the last 4 digits.