I like to do a bit-reversal on unsigned 32-bit integers; that is, if the original number in binary is f.i. 0111.0010.1111.0010.0001.1100.0101.1011, then the bit-reversal would be 1101.1010.0011.1000.0100.1111.0100.1110 (dots are for clarity). The naive algorithm would take 32 iterations in a loop and could look something like this (in C):

Code: Select all

```
unsigned bitreverse(unsigned n){
unsigned himask=1<<31;
unsigned lomask=1;
unsigned result=0;
int i;
for(i=0;i<32;i++){
if(n&lomask) result|=himask;
lomask<<=1;
himask>>=1;
}
return result;
}
```

Ideas are welcome.