divide each number by -2 until you get -1, or 1 (Remembering that
remainder is always +ve)
Ex
1)
-2 | 2 | 0
| -1 |
Interpret -1 as 11
so binary is 110
2)
-2 | 3 | 1
|-1|
Binary : 111
3)
-2 | 4| 0
|-2| 0
| 1|
Binary : 110
4)
-2 | 5| 1
|-2| 0
| 1|
Binary : 101
5)
can you plzz tel me y -1 is interpreted as 11 ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
code..
void base_minus2(int n)
{
int x,y;
if( n==0 ){
return ;
}
else
{
x = n % (-2) ;
if(n0 (n%2!=0)){
n=n-1;
x = 1;
}
base_minus2(n/(-2));
printf(%d,x);
}
}
--
You received this message because
@vikash: Because -1 = -2 + 1 = 1*(-2)^1 + 1(*-2)^0 = 11 in place
notation.
Dave
On Aug 30, 8:58 am, vikash jain vikash.ro...@gmail.com wrote:
can you plzz tel me y -1 is interpreted as 11 ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
kar lo be itna bhi nahi kar paate :):)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For
No need to handle -1 specially.
6)
-2 |-1| 1
| 1|
Binary : 11
On 2010-8-30 20:37, ANKIT AGGARWAL wrote:
divide each number by -2 until you get -1, or 1 (Remembering that
remainder is always +ve)
Ex
1)
-2 | 2 | 0
| -1 |
Interpret -1 as 11
so binary is 110
2)
-2 | 3 | 1