What does “>>>” in java mean?

前端 未结 3 456
情话喂你
情话喂你 2021-01-21 19:48

im trying to translate this code to python, but im having a hard time doing so, don\'t worry about the index values and variable names, I just want to know what the \">>>\" part

相关标签:
3条回答
  • 2021-01-21 20:30

    Thats the unsigned right shift operator. It's a bitwise operator that shifts a zero into the leftmost bit of your operand. Here - http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html.

    0 讨论(0)
  • 2021-01-21 20:46

    It's an "unsigned right shift".

    So, if your number (x) is 11110000 (in binary).

    x >>> 1 will be 01111000 (in binary).

    This is opposed to x >> 1 which will result in 11111000 (in binary).

    The >> tries to preserve the "sign bit" but the >>> does not.

    Note: I've assumed a 8-bit integer (or a byte in Java). The same thing holds for 2-byte and 4-byte integers.

    0 讨论(0)
  • 2021-01-21 20:52

    The "<<<" and ">>" are bit shift operators. Specifically,

    The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

    —— from The Java™ Tutorials - Bitwise and Bit Shift Operators

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