Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I can imagine no circumstance where this would be useful or helpful in any way.

The one application that stands out is encryption algorithms which do data-dependent rotates.



Well, that's not a bit-shift, it's a rotate.


What about circular rotates? a<<(x%32) & a>>(32-(x%32))


having 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.


a = 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...


0 & 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


You're right! My bad. Definitely meant to | it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: