How to add negabinary numbers?

4.2k Views Asked by At

A negabinary is a number with a base as -2. I want to add two such numbers. I know how to convert them into the corresponding decimal numbers but wanted to add them right away without conversion to decimal system.

For eg, if two numbers are 1011 and 1110, the output is 110001 in the negabinary addition. I understand the concept of a signed bit but could not comprehend this.

2

There are 2 best solutions below

11
On BEST ANSWER

You add them just like regular binary numbers, except the carry is negative and should be subtracted from each column instead of added to it. $$ \begin{align} 1\color{red}1\phantom{1}\color{red}1\phantom{11}&\\ 1011&\\ {}+1110&\\ \hline =110001& \end{align} $$ (I'm using the color red to signify a carry with a negative value.) For that last $\color{red}1$, note that translates to $1$ with a positive (black) carry of $1$ (as $-1$ in regular numbers is $11$ in negabinary).

For a more convoluted example, consider $$ \begin{align} 1\color{red}11\color{red}1\phantom{0000}&\\ 101010&\\ {}+101100&\\ \hline =11110110\end{align} $$ The two lone negative $1$'s each give a result of $1$ in their respective columns, and a positive (black) carry of $1$. The column where you now have three (black) $1$'s gives (as "normal") a result of $1$ and a negative (red) carry to the next column. And this ought to address anything that can possibly happen in a column when adding two numbers together.

In the case that we have four $1$'s in one column, we have 0 for that column and 1 for the two consecutive columns (as 4 in decimal is equivalent to 100 in negabinary). Here is an example: $$ \begin{align} &\\ 00101 (+5)&\\ {}+00111 (+3)&\\ \hline =11000 (+8)\end{align} $$

2
On

There's a good rule for negabinary addition, which is really easy to use, and comprises a set of three cases which account for all eventualities, and is "sign-transitive" in the sense that you can apply it in any position, be it a negative or positive place-value:

$1+1=110$

$1+1+1=111$

$1+11=0$

(I'm assuming $1+0=1$ is obvious)

I was trying to remember where I saw this but it's 8 minutes into this which contains some other valuable insights.