the Q. is
lets suppose i/p(n) = 10111001100010101101
now reverse above binary no. i.e. o/p =10110101000110011101

I think now its clear.
one method is
reverse()
{
int temp=0;
while(n>0) {
if(n&1) { temp=temp|1; temp<<=1; }
else temp<<=1;
n>>=2;
}
}

any efficient method ????


On Thu, Oct 15, 2009 at 8:55 AM, ankur aggarwal <ankur.mast....@gmail.com>wrote:

> @pradeep
> your ques is not clear..
>
>
> On Thu, Oct 15, 2009 at 7:58 AM, Arun <arunm...@gmail.com> wrote:
>
>>
>>
>> *
>>> n=(11101001>>2)|(**11101001<<4)
>>> *
>>> *n=(00111010)|(01000000)
>>>
>>> *
>>
>>
>> *11101001<<4 is 10010000*
>>
>>
>>
>>> *now n is 01111010*.....
>>>
>>>
>>> On Tue, Oct 13, 2009 at 9:18 AM, Raghavendra Sharma <
>>> raghavendra.vel...@gmail.com> wrote:
>>>
>>>> @Ankur I am assuming the integer to be 32 bits. actually it should be
>>>> 0xFFFFFFFF
>>>> step 1 :  temp =  (0xFFFFFFFF >> (32 - x)) & n;
>>>> step 2 :  n  =  (n  >> x) | ( temp << (32 -x));
>>>>
>>>> The first step extracts the lower x bits and second step moves upper
>>>> bits to left side and puts the lower x bits at the beginning.
>>>>
>>>> for example the integer is  0x12345678 and x = 4 then
>>>> temp = 0x8
>>>>
>>>> (n >> x) = 0x01234567 and temp << (32 - x) is 0x80000000
>>>>
>>>> and  (n >> x) | (temp << (32 -x)) ix 0x81234567
>>>>
>>>>
>>>> So temp will contain
>>>>
>>>> On Tue, Oct 13, 2009 at 12:07 AM, GauravNITW <gauravkis...@gmail.com>wrote:
>>>>
>>>>>
>>>>> How abt this..?
>>>>>
>>>>> for(i=0;i<x;i++)
>>>>>  {
>>>>>    res=no&1U;
>>>>>    no=no>>1;
>>>>>    if(res==1)
>>>>>      no=no|32768U;
>>>>>    else
>>>>>      no=no|0U;
>>>>>  }
>>>>>  printf("\nFinal value %u",no);
>>>>>
>>>>>
>>>>> On Oct 12, 8:11 pm, Raghavendra Sharma <raghavendra.vel...@gmail.com>
>>>>> wrote:
>>>>> > temp =  (0xFFFF >> (32 - x)) & n;
>>>>> > n  =  (n  >> x) | ( temp << (32 -x));
>>>>> >
>>>>> > On Mon, Oct 12, 2009 at 5:32 PM, ankur aggarwal <
>>>>> ankur.mast....@gmail.com>wrote:
>>>>> >
>>>>> >
>>>>> >
>>>>> > > *You are given a integer and you want to rotate the bits of the
>>>>> number by
>>>>> > > a value x. Consider the right rotation by x means the least
>>>>> significant x
>>>>> > > bits should go out from left and take the position of most
>>>>> significant x
>>>>> > > bits.*- Hide quoted text -
>>>>> >
>>>>> > - Show quoted text -
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Thanks & Regards
>>>
>>> Umesh kewat
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to