Oracle Interview Question

Bit Rotation function.

Interview Answer

Anonymous

Apr 17, 2017

Rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end. # Max number of bits BITS = 8 def left_rotate(number, bits): """ Function to left rotate a number by the given bit count. """ return int('1'*BITS, 2) & ((number > (BITS - bits)))