Mathematically calculate Bit Rotation

31 Views Asked by At

I am trying to calculate a cyclic bit rotation mathematically, but I am trying to avoid the use of mod operators, is there a way to do this,

This is what I have written so far

maxbits = 8
shift    = lambda integer, s : int((integer / (2**s)) - (integer / (2**s) % 1))
rotation = lambda integer, r : int(shift(integer, r) + ((integer % 2**r)*(2**(maxbits - r))))

https://math.stackexchange.com/a/83373/1025334, I did find this answer but my calculations I am having troubles calculating it, the answer isn't what's it's supposed to be.

I am using the mod to get rid of the decimal when shifting bits.