What is the difference between bitwise offset with 2 arrows and 3 arrows?

I have seen >>and >>>used. What is the difference and when to use each?

+4
source share
2 answers

The double arrows "→" and the triple arrows "→>" are defined in 32-bit integers, therefore, their execution in a variable will "convert" their so-called numbers that do not contain numbers to numbers. In addition, javascript numbers are stored as double precision floating-point values, so these operations can also lead to the loss of any precision bits above 32. "→" supports the sign bit (the result is a signed integer), and "→>" does not (the result represents an unsigned integer).

http://msdn.microsoft.com/en-us/library/342xfs5s%28v=vs.94%29.aspx

For a better explanation: fooobar.com/questions/1179 / ...

+2
source

. → > , (MSB). → . :

int x=-64;

System.out.println("x >>> 3 = "  + (x >>> 3));
System.out.println("x >> 3 = "  + (x >> 3));
System.out.println(Integer.toBinaryString(x >>> 3));
System.out.println(Integer.toBinaryString(x >> 3));

:

x >>> 3 = 536870904
x >> 3 = -8
11111111111111111111111111000
11111111111111111111111111111000
+6

Source: https://habr.com/ru/post/1531016/


All Articles