Possible Duplicate:
Best Algorithm for Bit Reversal ( from MSB->LSB to LSB->MSB) in C
Hi All, I had just written down a bit reversal function and its shown below.I feel its lengthy.So is there any faster and short method or any other alternative which you feel is much more faster and better.
Assuming integer is 4 bytes:
int BitReversal(unsigned int);
main()
{
unsigned int a;
printf("Enter any unsigned number:\n");
scanf("%d",&a);
BitReversal(a);
getch();
}
int BitReversal(unsigned int Num)
{
int i=0;
int Temp = Num;
unsigned int Res= 0;
int count = 31;
while(i<32)
{
Num = (Num>>i)&0x01;
Num = Num<<count;
Res|=Num;
count--;
i++;
Num = Temp;
}
printf("The num is %x",Res);
}
Thanks a lot
Maddy