I need to bit reverse 8-bit integers.
eg 208 (11010000) becomes 11 (00001011)
This works but it's too slow:
private short MyReverse(short a)
{
int[] order = new int[8];
for (int i = 0; i < 8; i++)
{
if ((a & Convert.ToInt32((Math.Pow(2, i)))) != 0)
{
order[7-i] = 1;
}
else
{
order[7-i] = 0;
}
}
double result = 0;
for (int i = 0; i < 8; i++)
{
result+=order[i]*Math.Pow(2,i);
}
return (short)result;
}
Anyone know a faster way?