Do you mean reverse each bit ie. 1110 to 0001 which could be done like this using the NOT operator:-
int val;
val = ~val;
Or do you mean reverse the order of the bits ie. 1110 to 0111 which could be done like this(assumes that your implementation uses 32bit ints):-
int val, temp, i;
val = 0xFFF03001; /*for example*/
temp = 0;
for (i=0; i < 32; ++i)
{
temp <<= 1; /* left shift one place */
temp |= (val & 1);
val >>= 1; /* right shift one place */
}
val = temp; /* val should now be 0x800C0FFF */
Hope this helps, sorry about the lack of explanation,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.