Search code examples
javascriptpythonbitwise-operators

Python equivalent of the JavaScript bitwise >>>


Is there an equivalent of >>> operator of JavaScript in Python. As per >>> definition of JavaScript, the operator,

Shifts right by pushing zeros in from the left, and let the rightmost bits fall off

So is there any direct operator in python as >> cannot do so in my opinion


Solution

  • x << y Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying x by 2**y.

    x >> y Returns x with the bits shifted to the right by y places. This is the same as integer-dividing x by 2**y.