# 4-digit 5's complement of a negative number

Let $n = -13, \ k = -24$

How do I find the 4-digit 5's complement of each number? What would be the result of $n + k$ in complement representation?

I understand how to calculate $n$-digit, 2's complement. I convert it to base 2, invert and add one.

Also, with positive numbers, let's say $n = 13, \ k = 24$, the 4-digit 5's complement would be $(5542)_{10}$ and $(5531)_{10}$. Correct? What would their addition be?

• Presumably, 5's complement works in base 5. You just invert (subtract from 4) all digits, and add 1. – Yuval Filmus Dec 4 '17 at 17:51

Let me demystify $$b$$'s complement.
Let $$b \geq 2$$ be an integer. Given a $$d$$-digit integer $$x$$ is base $$b$$, we want to find a $$d$$-digit integer $$y$$ such that $$y \equiv -x \pmod{b^d}$$. Why is this useful? Suppose that $$z$$ is also a $$d$$-digit integer, and assume that $$z-x \geq 0$$. Then $$z-x \equiv z+y \pmod{b^d}$$, and so if we add $$z$$ and $$y$$ and ignore the carry, we will get $$z-x$$ to achieve subtraction.
How do we find $$y$$, the $$b$$'s complement of $$x$$? We take $$y =k\times b^d-x= b^d-x = (b^d-1-x)+1$$ (with $$k\in \mathbb{Z}$$, let $$k = 1$$). Now the representation of $$b^d-1$$ in base $$b$$ consists of $$d$$ digits of $$b-1$$, so $$b^d-1-x$$ is obtained by inverting all the digits of $$x$$ (subtracting them from $$b-1$$). This is $$b$$'s complement: the $$b$$'s complement $$y$$ of $$x$$ is obtained by inverting all digits and adding 1.
$$n$$'s complement of $$x$$ in the base of $$n$$ means finding $$x'$$ such that $$x+x'=0$$.
@Yuval Filmus has given clear explanation on the general method of finding $$b$$'s complement; while in your case, it is easy to find mistakes that there shouldn't be any $$5$$ in the digit: $$|n|=13_{10}=0023_5\\|k|=24_{10}=0044_5$$ Subtracting each digit of $$n,k$$ from $$(b-1=4)$$ and adding $$1$$, we get: $$-n=4422_5\\-k=4401_5$$ Quick check: $$-(n+k)=4422_5+4401_5=4323_5\Rightarrow n+k=0122_5=37$$