Zero fill right shift in python

后端 未结 1 1715
后悔当初
后悔当初 2021-01-16 04:06
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 w

1条回答
  •  野的像风
    2021-01-16 04:14

    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)
    

    0 讨论(0)
提交回复
热议问题