For some memory masking operations I need a bitwise-rotation functionality for unsigned integral types. I came across to the solutions based on the wiki article, but have not found a variation for a function for bitwise-rotation within an "arbitrary" field of bits. Therefore, I have extended the solution of Johnsolution of John Regehr, and now I want some feedback from you. I would also appreciate ofany advice on using mechanisms provided by the C++ core-language upto language up to C++14 (without the use of the std-namespacestd namespace).
#include <iostream>
#include <vector>
#include <bitset>
uint64_t CircShift (uint64_t x, uint8_t n, uint8_t bitwidth)
{
return ((x<<n)&((1<<bitwidth)-1)) | (x>>(bitwidth-n));
}
int main()
{
uint64_t var=0b000110100110;
var=CircShift(var,2,9);
std::cout<<std::bitset<12>(var);
}