how can i shift bits without loosing any information... heard something about bit rotating but i'm not really clear how it works... thankful for every answer
rotating bits means to shift in bits that were previously shifted out.
There's no operator for this in C++, but it can be accomplished with bitwise operators:
1 2 3 4 5 6 7 8 9 10
typedefunsignedchar byte;
//...
byte rotateright(byte v)
{
byte temp = v & 1; // extract the low bit
v >>= 1; // shift right
v |= (temp << 7); // put the previous low bit in the high bit
return v;
}