Bitwise rotate of integral

Per Nordlöw per.nordlow at gmail.com
Mon Jan 7 14:43:29 UTC 2019


On Monday, 7 January 2019 at 14:39:07 UTC, Per Nordlöw wrote:
> What's the preferred way of doing bitwise rotate of an integral 
> value in D?
>
> Are there intrinsics for bitwise rotation available in LDC?

I just found this

     ulong rotateLeft(ulong x, ubyte bits)
     {
         return (x << bits) | (x >> (64 - bits));
     }

Questions:
- Is this a good implementation for the ulong case?
- Should we use >> or >>> ?
- What's the preferred type for `bits`, ubyte, or uint or making 
it a template parameter?


More information about the Digitalmars-d-learn mailing list