43 lines
1.3 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// operators/URShift.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Test of unsigned right shift.
public class URShift {
public static void main(String[] args) {
int i = -1;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(i));
2015-06-15 17:47:35 -07:00
i >>>= 10;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(i));
2015-06-15 17:47:35 -07:00
long l = -1;
2015-11-03 12:00:44 -08:00
System.out.println(Long.toBinaryString(l));
2015-06-15 17:47:35 -07:00
l >>>= 10;
2015-11-03 12:00:44 -08:00
System.out.println(Long.toBinaryString(l));
2015-06-15 17:47:35 -07:00
short s = -1;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(s));
2015-06-15 17:47:35 -07:00
s >>>= 10;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(s));
2015-06-15 17:47:35 -07:00
byte b = -1;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(b));
2015-06-15 17:47:35 -07:00
b >>>= 10;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(b));
2015-06-15 17:47:35 -07:00
b = -1;
2015-11-03 12:00:44 -08:00
System.out.println(Integer.toBinaryString(b));
System.out.println(Integer.toBinaryString(b>>>10));
2015-06-15 17:47:35 -07:00
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
11111111111111111111111111111111
1111111111111111111111
11111111111111111111111111111111111111111111111111111111111
11111
111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
1111111111111111111111
2015-09-07 11:44:36 -06:00
*/