32 program [32] left right
Title: takes an integer from 4 to 7 from the right end of a.
Program analysis: consider this:
(1) first makes a right four.
(2) is provided a low-4 are all 1, the rest is a number of 0. Available ~ (~ 0 << 4)
(3) above will be both & calculation.
package cskaoyan; public class cskaoyan32 { @org.junit.Test public void logicalShift() { java.util.Scanner in = new java.util.Scanner(System.in); System.out.println("input a number:"); int a = in.nextInt(); int b = a >> 4; int c = ~(~0 << 4); int d = b & c; System.out.println(a + " " + d); in.close(); } }