问题
function(e, t) {
return e << t | e >>> 32 - t
}
I have this method in js, I do not understand in deep about shift operation. I want to write that in python. How can I write the equivalent code in python as it does not support Zero Fill Right Shift Operator as in JS >>>
.
回答1:
There is not a built-in zero fill right shift operator in Python, but you can easily define your own zero_fill_right_shift
function:
def zero_fill_right_shift(val, n):
return (val >> n) if val >= 0 else ((val + 0x100000000) >> n)
Then you can define your function:
def f(e, t):
return e << t or zero_fill_right_shift(e, 32 - t)
来源:https://stackoverflow.com/questions/55014710/zero-fill-right-shift-in-python