[Math] How to add negabinary numbers

arithmeticbinarybinary operations

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.

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

Related Question