[algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread ANKIT AGGARWAL
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)

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread vikash jain
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

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Dhritiman Das
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

[algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Dave
@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

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Piyush Verma
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

Re: [algogeeks] Re: Converting a decimal number to base -2

2010-08-30 Thread Terence
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