/Users/lyon/j4p/src/bookExamples/appJBitOps/DisplayString.java

1    /* 
2     * @author Douglas A. Lyon 
3     * @version  Oct 28, 2002.9:35:39 AM 
4     */ 
5    package bookExamples.appJBitOps; 
6     
7    public class DisplayString { 
8     
9        public static void main(String args[]) { 
10           int number1 = 960; 
11           int display_mask = 1 << 15; 
12           printlnBits("number1     \t          ", number1); 
13           printlnBits("display_mask\t          ", display_mask); 
14           printlnBits("number1<< 8 \t          ", number1 << 8); 
15           printlnBits("number1>> 8 \t          ", number1 >> 8); 
16           printlnBits("display_mask | number1\t", display_mask | number1); 
17           printlnBits("display_mask & number1\t", display_mask & number1); 
18           printlnBits("display_mask ^ number1\t", display_mask ^ number1); 
19           printlnBits("display_mask ^~number1\t", display_mask ^ ~number1); 
20       } 
21    
22       public static void printlnBits(String s, int x) { 
23           System.out.println(s + "= " + Integer.toString(x, 2)); 
24       } 
25    
26   } 
27