language-agnosticgraphicsbit-manipulationhlslmath

rightrotate without bitwise operators


How can I implement the rightrotate (and leftrotate) operations on 32-bit integers without using any bitwise operations?

I need this because High-Level Shader Language (HLSL) does not allow bitwise operations on numbers (until version 4), and I require right rotation for a specific shader I'm trying to implement.


Solution

  • For unsigned integers, divide by 2 and add 2^32 if the number was odd, for right rotate. For left, multiply by two and add 1 if it was above 2^32 - 1.