Is it possible to rotate whole variable?
Something likae 0101 0101 0101 0101 -> 1010 1010 1010 1010?
If yes, how? I found so many examples on how to rotate few bits but not the whole variable?
Is it possible to rotate whole variable?
Something likae 0101 0101 0101 0101 -> 1010 1010 1010 1010?
If yes, how? I found so many examples on how to rotate few bits but not the whole variable?
Bit-shifting is easily done with bit-wise operators.
There are no native C operators that do a rotate, but you can easily roll your own function to do this. This just requires a bit check, a single shift, and (if necessary) a bit set ... repeated as many times as needed.
Code:unsigned short rotate( unsigned short value ) { return (value << 1) | ((value >> 15) & 1); }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)