Re: [algogeeks] Re: Represent a number in base of minus 2 ????
@zyro May be this solves your problem... #include iostream using namespace std; int main() { int no; char digit[50]; int counter=0; cin no; do { if ( no% 2 == 0) { digit[counter++]='0'; } else { digit[ counter++ ]='1'; } if ( no 0 ){ no = (1 - no)/2; } else if(no0){ no = -no/2; } } while ( no ); for ( int i = counter- 1; i = 0; i--) { cout digit[ i ] ; } cout endl; return 0; } On Sun, Jan 29, 2012 at 8:51 PM, saurabh singh saurab...@gmail.com wrote: Use a pen and paper:) Generate a few numbers in base -2 by hand.You will get the logic. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sun, Jan 29, 2012 at 11:44 PM, Zyro vivkum...@gmail.com wrote: 0 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- -Sharad Dixit B.Tech(IT) Indian Institute of Information Technology Allahabad - We aim above the mark to hit the mark. ~ Ralph Waldo Emerson -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Represent a number in base of minus 2 ????
@Sharad.. Thanx.. :) On Jan 31, 2:42 am, sharad dixit sharad.emine...@gmail.com wrote: @zyro May be this solves your problem... #include iostream using namespace std; int main() { int no; char digit[50]; int counter=0; cin no; do { if ( no% 2 == 0) { digit[counter++]='0'; } else { digit[ counter++ ]='1'; } if ( no 0 ){ no = (1 - no)/2; } else if(no0){ no = -no/2; } } while ( no ); for ( int i = counter- 1; i = 0; i--) { cout digit[ i ] ; } cout endl; return 0; } On Sun, Jan 29, 2012 at 8:51 PM, saurabh singh saurab...@gmail.com wrote: Use a pen and paper:) Generate a few numbers in base -2 by hand.You will get the logic. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sun, Jan 29, 2012 at 11:44 PM, Zyro vivkum...@gmail.com wrote: 0 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- -Sharad Dixit B.Tech(IT) Indian Institute of Information Technology Allahabad --- -- We aim above the mark to hit the mark. ~ Ralph Waldo Emerson -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Represent a number in base of minus 2 ????
@Anika 7 = 1*((-2)^4) + 1*((-2)^3) + 0*((-2)^2) + 1*((-2)^1) + 1*((-2)^0) ... simlilary for other numbers... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Represent a number in base of minus 2 ????
Use a pen and paper:) Generate a few numbers in base -2 by hand.You will get the logic. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sun, Jan 29, 2012 at 11:44 PM, Zyro vivkum...@gmail.com wrote: 0 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.