Hi Guys,
First post!!
I come from micro controller land where we speak RISC asm,
so C has been a little difficult to grasp when it comes to dealing with bits.
I was reading this thread:
http://cboard.cprogramming.com/c-pro...yte-array.html
and got this function working:
The trouble I'm having is reversing it to make a new function to rotate right instead of left.Code:void shiftl(void *object, size_t size) {
unsigned char *byte;
for ( byte = object; size--; ++byte ) {
unsigned char bit = 0;
if ( size ) {
bit = byte[1] & (1 << (CHAR_BIT - 1)) ? 1 : 0;
}
*byte <<= 1;
*byte |= bit;
}
}
I know that object is the beginning of the array and size is the size,
so to shift right I should begin from object+size to make the for
loop run backwards. I don't know what ++byte is for.
Also, does;
mean if size does not equal zero? or greater than zero?Code:if ( size ) {}
I've never seen that before.
I see where the byte is shifted, but don't understand:
any help appreciated, thanks :)Code:*byte |= bit;