Is there a function in Apple’s library that can reverse the order of the bits in a short?
0000 0011 -> 1100 0000
Thanks in advance.
Method used:
unsigned int NO_OF_BITS = sizeof(num) * 8;
unsigned int reverse_num = 0;
int i;
for (i = 0; i < NO_OF_BITS; i++)
{
if((num & (1 << i)))
reverse_num |= 1 << ((NO_OF_BITS - 1) - i);
}
It sounds like you are trying to reverse the bit sequence of the give byte.
There are lots of way to do this efficiently. Have a look at http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious
This site contains lots of tricks when working with bits.