43 lines
1.3 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// operators/URShift.java
2016-12-30 17:23:13 -08:00
// (c)2017 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.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2016-01-25 18:05:55 -08:00
// Test of unsigned right shift
2015-06-15 17:47:35 -07:00
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
*/