What is the difference between operator >>> in Java and JavaScript?

后端 未结 1 1402
我在风中等你
我在风中等你 2020-12-20 10:45

JavaScript code:

alert( -123456 >>> 0 ); // Prints 4294843840

Java code:

System.out.println( -123456 >>>          


        
1条回答
  •  北海茫月
    2020-12-20 11:24

    Both are the logical right shift, but JavaScript has some weirdness in how it handles numbers. Normally numbers in JavaScript are floats, but the bitwise operations convert them to unsigned 32 bit integers. So even though the value looks like it shouldn't change, it converts the number to a 32 bit unsigned integer.

    The value that you see 4294843840 is just the same bits as -123456, but interpreted as unsigned instead of signed.

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