I'm currently working in C/C++, and I have a uint64_t. I need to do a bitwise rotation on the top 32 bits and the bottom 32 bits separately. So for example, if my input is
| | | |
0000 0000 0000 0000 0000 0000 0000 1101 0000 0000 0000 0000 0000 0000 0000 0111
and I need to rotate 2 bits to the right, the proper output is
| | | |
0100 0000 0000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0000 0000 0001
The obvious method is to make a temporary 32-bit number and do the rotation operations on that separately, but is there a different, efficient way of doing this?
You can use same memory in 2 modes - as
uint_64_t, and asarray[2]ofuint32_t. Easiest and transparent way - to use union:Thereafter, just use fields of this union: