Here’s a Rotation function to recycle bits from the ‘bit bucket’,
Questions:Code: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; }
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.




Reply With Quote