Given a pattern of 1,2,4,8 neing N,E,S,W then the bits represent connections in this arrangement:
WSEN
Then a clockwise rotation is:
- left-shift <<
- AND with the 5th bit (16)
- If true, subtract 15 (-16, +1) to get the LSB turned on
And an anti-clockwise rotation is:
- AND with 1st bit (1)
- zero-fill right-shift >>>
- If step 2 is true, add 8 to get the MSB turned on