-1

I receive a piece of code written in java, that uses the operation >>>, after a quick search, I found out that it "shifts a zero into the leftmost position", but I could not find a equal operation in python.

What would be the similar operation for the following code in python?

((CRC & 0xFF00) >>> 8)
  • https://www.geeksforgeeks.org/python-bitwise-operators/ – ninjajosh5 Nov 05 '21 at 13:40
  • 2
    I'm pretty sure that python's `>>` is identical to Java's `>>>`, and it doesn't have a signed bitshift (which copies the most significant bit when shifting, rather than using 0) – Green Cloak Guy Nov 05 '21 at 13:40
  • In Python, `CRC & 0xFF00` would be equivalent to `CRC & 0x0FF00`. IIRC, if you wanted sign extension, you would do `CRC & 0x1FF00` to get an appropriately sign-extended result from the following `>>`. – chepner Nov 05 '21 at 13:46
  • python docs for [bitwise operations on integers types](https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types) – diggusbickus Nov 05 '21 at 13:47

1 Answers1

0

as far as i know python's >> does exactly that (what java's >>> does). and the & does the same is python as in java.

(CRC & 0xFF00) >> 8
Kesslwovv
  • 639
  • 4
  • 17