4 ms·
What about circular rotates? a<<(x%32) & a>>(32-(x%32))
by nostrebored 12y ago
What about circular rotates? a<<(x%32) & a>>(32-(x%32))
- thaumasiotes 12y agohaving worked an example to see how this could possibly work, I feel compelled to note for other people who might have wondered that a circular rotate looks like "(a << (x % 32)) | (a >> (32 - (x % 32)))"; as written, you're replacing every bit with zero.
- nostrebored 12y agoa = 1111 0000 0000 1111 1111 0000 0000 1111 a << 37 == a << (37 % 32) == a << 5 == 0000 0001 1111 1110 0000 0001 1110 0000 a >> (32 - (37 % 32)) == a >> 27 == 0000 0000 0000 0000 0000 0000 0001 1110 anding the two together you get == 0000 0001 1111 1110 0000 0001 1111 1110 which is a circular rotation of the bit string...
- thaumasiotes 12y ago0 & 1 is not 1, it's 0. 0000 0001 1111 1110 0000 0001 1110 0000 & 0000 0000 0000 0000 0000 0000 0001 1110 ----------------------------------------- 0000 0000 0000 0000 0000 0000 0000 0000
- nostrebored 11y agoYou're right! My bad. Definitely meant to | it.