Circular-shift with variable bitlength
I think the function looks good. It does what it's supposed to do when the input is correct. However, if the input number x is larger or equal to 1&lt;&lt;bitwidth, the behavior is undefined. To rectify this, I suggest:

uint64_t CircShift(uint64_t x, uint8_t n, uint8_t bitwidth)
{
    return ((x&lt;&lt;n)&amp;((1&lt;&lt;bitwidth)-1)) | 
           ((x&amp;((1&lt;&lt;bitwidth)-1))&gt;&gt;(bitwidth-n));
}


Just add another mask to the right-shifted part. Also note that for shifts that are bigger than 64 bits, both your original function and my new function behave strangely. To rectify this, you can use the fact that a circular shift by bitlength steps simply give you the original number:

uint64_t CircShift(uint64_t x, uint8_t n, uint8_t bitwidth)
{
    return ((x&lt;&lt;(n%bitwidth))&amp;((1&lt;&lt;bitwidth)-1)) 
        | ((x&amp;((1&lt;&lt;bitwidth)-1))&gt;&gt;(bitwidth-(n%bitwidth)));
}