the3rdStorm
February 14th, 2004, 01:28 PM
Here’s a Rotation function to recycle bits from the ‘bit bucket’,
unsigned char rol(unsigned char val) {
int highbit;
if(val & 0x80) // 0x80 is the high bit only
highbit = 1;
else
highbit = 0;
// Left shift (bottom bit becomes 0):
val <<= 1;
// Rotate the high bit onto the bottom:
val |= highbit;
return val;
}
Questions:
1. Why use 0x80(128) to check for the high bit?
2. Can you please explain the use of the Rotation?
3. Is there any other ways to do the Rotation?
Thanks.
unsigned char rol(unsigned char val) {
int highbit;
if(val & 0x80) // 0x80 is the high bit only
highbit = 1;
else
highbit = 0;
// Left shift (bottom bit becomes 0):
val <<= 1;
// Rotate the high bit onto the bottom:
val |= highbit;
return val;
}
Questions:
1. Why use 0x80(128) to check for the high bit?
2. Can you please explain the use of the Rotation?
3. Is there any other ways to do the Rotation?
Thanks.