2

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?

D.W.
  • 167,959
  • 22
  • 232
  • 500
yarafoudah
  • 147
  • 4

2 Answers2

1

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.

Luke Mathieson
  • 18,373
  • 4
  • 60
  • 87
Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
0

$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$

Chris Tang
  • 135
  • 8