Best practices for circular shift (rotate) operations in C++

前端 未结 16 1782
情深已故
情深已故 2020-11-22 00:09

Left and right shift operators (<< and >>) are already available in C++. However, I couldn\'t find out how I could perform circular shift or rotate operations.

16条回答
  •  长发绾君心
    2020-11-22 00:39

    another suggestion

    template
    inline T rotl(T x, unsigned char moves){
        unsigned char temp;
        __asm{
            mov temp, CL
            mov CL, moves
            rol x, CL
            mov CL, temp
        };
        return x;
    }
    

提交回复
热议问题