Quote Originally Posted by usnsailorjeoff
...COuld someone please explain the logic behind this function? I don't quite understand what the << and >> does???...
This is simple trial-and-error method: try adding various powers of 2 to the test value and check if it is over the target value - then subtract that last value.
>> and << are binary shift operators (right and left).
>>= - shift with assignment, j >>= 1 is the same as j = j >> 1