A rotate (or circular shift) is a shift with the ends joined. The bit that falls off one end comes back in at the other.
- Rotate right: every bit moves one place toward Q0, and the old Q0 goes into Q3.
1101→1110. - Rotate left: every bit moves one place toward Q3, and the old Q3 goes into Q0.
1101→1011.
No information is lost, so rotations are reversible: rotating right by k undoes rotating left by k. After n single-place rotations, an n-bit register is back where it started. Rotating by k places is the same as rotating by k mod n.
In hardware: a shift register with its serial input wired to its own serial output. A shift-right register with SI = Q0 rotates right. A universal shift register does the same with SIR wired to Q0.
Where it is used:
- A register that rotates forever, started with a single 1, is a ring counter.
- Cryptography and hashing algorithms mix bits with rotations.
- Most processors have rotate instructions (ROL and ROR), sometimes with the carry flag included in the loop.
Compare a plain shift, where the bit that leaves is lost and a fixed value (0, or the sign bit) enters.