Depends on how you define 'efficient'. You're not going to be able to avoid doing about 64 bit comparisons for every rotation.
Code:
#include <stdio.h>
void rotbits (unsigned char bits[8]) {
int i, j;
unsigned char i_mask, j_mask;
// Change the direction of the rotation by changing the direction of the masks
for (i = 0, i_mask = 0x01; i < 8; ++i, i_mask <<= 1)
for (j = 7, j_mask = 0x80; j > i; --j, j_mask >>= 1)
// If the bits are not the same, flip both bits
if (((bits[i] & j_mask) != 0) != ((bits[j] & i_mask) != 0)) {
bits[i] ^= j_mask;
bits[j] ^= i_mask;
}
return;
}
int main (void) {
unsigned char foo[8] = {0xFF, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00};
int i;
for (i = 0; i < 8; ++i) {
printf ("%2X\n", foo[i]);
}
printf ("rotate...\n");
rotbits (foo);
for (i = 0; i < 8; ++i) {
printf ("%2X\n", foo[i]);
}
return 0;
}