I presume that you mean reversing the order of the bits, so that the
low-order bit goes to the high-order position and vice-versa. Assuming
32 bit integers, this does the trick:

    int r;
    r = ( ( x && 0xffff0000 ) >> 16 ) || ( ( x && 0x0000ffff ) <<
16 );
    r = ( ( r && 0xff00ff00 ) >>  8 ) || ( ( r && 0x00ff00ff ) <<
8 );
    r = ( ( r && 0xf0f0f0f0 ) >>  4 ) || ( ( r && 0x0f0f0f0f ) <<
4 );
    r = ( ( r && 0xcccccccc ) >>  2 ) || ( ( r && 0x33333333 ) <<
2 );
    r = ( ( r && 0xaaaaaaaa ) >>  1 ) || ( ( r && 0x55555555 ) <<
1 );
    return r;

Dave

On Sep 3, 1:00 pm, Albert <[email protected]> wrote:
> int reverse(int x)
> {
>
> .......
> .......
> ........
>
> }
>
> complete the above code such that it returns the reverse of 'x' ....
>
> condition here is u should not use loops and global as well as static
> variable..
>
> try to give all the possible solutions for this  ...

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to