I dont have any idea how i convert deciaml using negetive base 2? i googling today long time but couldn't find any solution. can any tell me process? i need to learn it .
How I convert Decimal Using negetive Base 2?
-
0@Mok-KongShen: You can do arithmetic with a negative base just like you can with a positive base. The rules get weird, though. You no longer need a minus sign to express any integer, positive or negative. As to possible uses, I have no idea. – 2012-10-19
2 Answers
You can do it by recursion. Let me write numbers in base $-2$ in brackets, and decimal numbers without, so that $[0]=0$, $[1]=1$, $[10]=-2$, and $[11]=-1$. I listed these for a reason: They are all the numbers in base $-2$ with at most two digits. Now note that if you add a zero to the right end of a number in this base, the number is multiplied by $-2$. Therefore, if you add two zeros at the end, the number is multiplied by four. This is useful.
To write a number $n$ in base $-2$, reduce it by writing $n=4q+r$ with the “remainder” $r\in\{-2,-1,0,1\}$. Write $r$ as two digits, figure out the representation of $k$ recursively, and append the digits of $r$ at the end.
Here is an example: $ -17=-4\cdot4-1=(-1\cdot4)\cdot4+[11]=([11]\cdot4)\cdot4+[11]\\ =[1100]\cdot4+[11]=[110000]+[11]=[110011]. $ To check that: The final bracket is $-32+16-2+1=-17$.
-
0**Erratum:** I just noticed that I wrote $k$ where it should be $q$. I will refrain from editing the answer in order to avoid bumping the question to the front page. – 2015-08-09
One can use the standard algorithm for converting from one base to another. Divide by the target base $b$ to get an integer quotient and a remainder in the chosen range of digits, generally but not always $\{0,\dots,|b|-1\}$; replace the original number by the quotient and repeat; continue until you get a quotient of $0$, and read the remainders in reverse order. For example, to convert $-19$ to base $-2$:
$\begin{align*} -19&=-2\cdot 10+\color{red}{1}\\ 10&=-2\cdot(-5)+\color{red}{0}\\ -5&=-2\cdot3+\color{red}{1}\\ 3&=-2\cdot(-1)+\color{red}{1}\\ -1&=-2\cdot1+\color{red}{1}\\ 1&=-2\cdot0+\color{red}{1}\\ 0&=-2\cdot0 \end{align*}$
Reading the remainders (in red) from the bottom up, we find that $-19=111101_{-2}$. As a check,
$\begin{align*} 1\cdot(-2)^5&+1\cdot(-2)^4+1\cdot(-2)^3+1\cdot(-2)^2+0\cdot(-2)^1+1\cdot(-2)^0\\ &=-32+16-8+4+1\\ &=-19\;. \end{align*}$
Added: Here are a couple more examples.
$\begin{align*} 4&=-2\cdot(\color{blue}{-2})+\color{red}{0}\\ \color{blue}{-2}&=-2\cdot\color{green}{1}+\color{red}{0}\\ \color{green}{1}&=-2\cdot0+\color{red}{1}\;, \end{align*}$
so $4=100_{-2}$.
$\begin{align*} 7&=-2\cdot(\color{blue}{-3})+\color{red}{1}\\ \color{blue}{-3}&=-2\cdot\color{green}{2}+\color{red}{1}\\ \color{green}{2}&=-2\cdot(\color{blue}{-1})+\color{red}{0}\\ \color{blue}{-1}&=-2\cdot\color{green}{1}+\color{red}{1}\\ \color{green}{1}&=-2\cdot0+\color{red}{1}\;, \end{align*}$
so $7=11011_{-2}$.
-
0@Raihan: I added a couple of examples. However, I have not tried to justify the algorithm or explain it in detail, because it’s a standard algorithm for changing bases. – 2012-10-19