Bit rotation question/challenge

burt invalid_email_address at cab.abc
Sat Jan 30 13:30:49 UTC 2021


I have a static array of `ubyte`s of arbitrary size:

```d
ubyte[4] x = [ // in reality, ubyte[64]
     0b00001000,
     0b00000001,
     0b00010101,
     0b11110010,
];
```

Now I want to bit-rotate the array as if it is one big integer. 
So:

```d
ubyte[n] rotateRight(size_t n)(ref const ubyte[n] array, uint 
rotation)
{
     // ?
}
// same for rotateLeft

ubyte[4] y = [
     0b11111001,
     0b00000100,
     0b00000000,
     0b10001010,
];
assert(x.rotateRight(9) == y);
assert(y.rotateLeft(9) == x);
```

Any ideas how this could be achieved? I.e. what should go at the 
"?" for rotateRight and rotateLeft?


More information about the Digitalmars-d-learn mailing list