int reverse(int n)
{
   int i=9*( abs(n/10 - n%10) );
   return i;
}

On Wed, Aug 24, 2011 at 9:56 PM, Dave <dave_and_da...@juno.com> wrote:

> @Anika: So you want to reverse the digits of the decimal
> representation of a number. Extracting decimal digits requires
> division and modulus by 10. Normally this is done by division, but as
> a different recent thread has shown, division can be accomplished by
> bit operations, comparisons, and subtraction.
>
> This is the kind of computation you should go through to reverse the
> decimal digits of a number...
>
> int reverse( int n );
> {
>    int i = 0;
>    while( n )
>    {
>        i = i * 10 + n % 10;
>        n /= 10;
>    }
>    return i;
> }
>
> Now, if you want, you can dig though the other postings for the
> division algorithm. A simple modification of that algorithm can return
> the modulus (remainder) instead of or in addition to the quotient.
> Multiplication by 10 can be done with bit operations as i << 3 + i <<
> 1.
>
> Dave
>
> On Aug 11, 12:57 pm, Anika Jain <anika.jai...@gmail.com> wrote:
> > reverse of a no. means.. reverse of 39 is 93..
> > but i dont get it how can we reverse a no. by bitwise operator...
> >
> >
> >
> > On Thu, Aug 11, 2011 at 11:11 PM, manvir siyo <manis...@gmail.com>
> wrote:
> > > please tell me abt the pattern of de shaw company..
> > > please
> >
> > > On Thu, Aug 11, 2011 at 11:06 PM, paul suganthan <
> paul.sugant...@gmail.com
> > > > wrote:
> >
> > >> You are trying to reverse the bits. not the number.
> > >> This will not work for bits also!
> >
> > >> If given input is 1101 0011
> > >> you will get
> > >> 0010 1100
> >
> > >> On Thu, Aug 11, 2011 at 11:01 PM, Naren s <sweetna...@gmail.com>
> wrote:
> >
> > >>> not 100% sure if this is what you are asking for but here it goes.
> >
> > >>> you have a number 11110000 (binary) and you want 00001111 (binary)?
> >
> > >>> you want to use the xor operator ^
> >
> > >>> value = 0xf0; //11110000 binary
> > >>> printf("before %d\n");
> > >>> value ^= 0xff; //11111111 binary
> > >>> printf("after%d\n");
> >
> > >>> output:
> > >>> before 240
> > >>> after 15
> >
> > >>> 240 in binary is 11110000
> > >>> 15 in binary is 00001111
> >
> > >>> <
> http://wiki.answers.com/Q/How_do_you_reverse_a_number_using_bitwise_o...>
> >
> > >>> On Thu, Aug 11, 2011 at 10:43 PM, Rajeshwar Patra <
> > >>> rajeshwarpa...@gmail.com> wrote:
> >
> > >>>> how can we reverse a number using bitwise operators?
> >
> > >>>> --
> > >>>> *Rajeshwar Patra,*
> > >>>> *MCA final year,*
> > >>>> *Nit Durgapur*
> >
> > >>>>  --
> > >>>> 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.
> >
> > >>> --
> > >>> *Narayanan S,*
> > >>> B.E., C.S.E., (final year),
> > >>> College Of Engineering Guindy,
> > >>> Anna University,
> > >>> Chennai-25.
> >
> > >>>  --
> > >>> 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.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.

Reply via email to