x = 0; while( n ){ x <<= 1; x = x | ( n & 1); n >>= 1; } return x;
On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam <puneet.nsi...@gmail.com>wrote: > sorry guys.. dont check the above siolution.. its wrong...!!! > misread it.. > > > On 7/22/11, Puneet Gautam <puneet.nsi...@gmail.com> wrote: > > check this out: Considering all 4 bytes of int with no left or right > > shifts..!! > > ;) > > > > main() > > { unsigned int i,j,k,no=1; > > j=4; > > for(k=0;k<32;k++) > > no*=2; > > no=no-j; > > cout<<"\n The reverse is"<<no; > > getch(); > > return 0; > > } > > > > On 7/22/11, nicks <crazy.logic.k...@gmail.com> wrote: > >> see this > >> > >> http://geeksforgeeks.org/?p=726 > >> > >> On Fri, Jul 22, 2011 at 4:29 AM, adhyetha <ranjith.kaga...@gmail.com> > >> wrote: > >> > >>> reverse(int n) > >>> { > >>> int i, result = 0; > >>> > >>> for(i = 0; i < 32; i++) > >>> result |= ((n >> i) & 1) << (31 - i); > >>> } > >>> > >>> > >>> .... assuming 32 bit integer to be reversed and assuming all 32 bits > >>> to be reversed.. i.e 100101 reverses to > >>> 10100100000000000000000000000000 > >>> > >>> -- > >>> 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. > >>> > >>> > >> > >> -- > >> 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. > >> > >> > > > > -- > 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. > > -- 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.