JAVA关于位运算符



JAVA关于位运算符。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ex_8_java;

/**
*
* @author Administrator
*/
public class Ex_8_JAVA {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int sh1=10,sh2=20;
int sh3;
sh3=sh1&sh2;
System.out.println(“&:”+sh3);
sh3=sh1|sh2;
System.out.println(“|:”+sh3);
sh3=sh1^sh2;
System.out.println(“^:”+sh3);
sh1^=sh2;
sh2^=sh1;
sh1^=sh2;
System.out.println(“利用^在不占用任何中间存储单元的时候交换sh1、sh2的值:\nsh1=” + sh1 + “\t\tsh2=” + sh2);
sh3=~sh3;
System.out.println(“sh3=”+sh3);
sh3=sh3<<6;
System.out.println(“sh3=”+sh3);
sh3=sh3>>5;
System.out.println(“sh3=”+sh3);
}

}