Thinking in Java Fourth Edition Bruce Eckel Chapter 2 Exercise 12
Exercise 12: Start with a number that is all binary ones. Left shift it, then use the unsigned right-shift operator to right shift through all of its binary positions, each time displaying the result using Integer.toBinaryString( ).
Solution:
publicclass RightShiftTest2 { publicstaticvoid main(String[] args) { int h =-1; System.out.println(Integer.toBinaryString(h));
h <<=10; System.out.println(Integer.toBinaryString(h)); for(int i =0; i <32; i++) {
h >>>=1; System.out.println(Integer.toBinaryString(h)); } } }