Bitwise rotate of integral

Alex sascha.orlov at gmail.com
Mon Jan 7 14:53:26 UTC 2019


On Monday, 7 January 2019 at 14:43:29 UTC, Per Nordlöw wrote:
> 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?

There are
https://dlang.org/phobos/core_bitop.html#.rol
and
https://dlang.org/phobos/core_bitop.html#.ror

But it seems the implementation is like yours.


More information about the Digitalmars-d-learn mailing list