//位运算符publicclassTestBit{publicstaticvoidmain(String[] args){// TODO Auto-generated method stubint a =31;
System.out.println(a <<3);//交换两个数的位置//方法一:缺点是需要定义一个新的变量int c =10;int b =20;
System.out.println("开始:");
System.out.println("c = "+ c);
System.out.println("b = "+ b);int temp;
temp = c;
c = b;
b = temp;
System.out.println("此时结果为:");
System.out.println("c = "+ c +"\n"+"b = "+ b);//方法二;缺点:当b,c的值很大时就有可能溢出
c = b + c;//c = 10 + 20
b = c - b;// b = 10 + 20 - 20
c = c - b;//c = 10 + 20 - 10
System.out.println("此时结果为:");
System.out.println("c = "+ c);
System.out.println("b = "+ b);//方法三:优点是不创建新的变量
c = c ^ b;
b = c ^ b;//(c ^ b) ^ b == c
c = c ^ b;//(c ^ b) ^ c == b
System.out.println("此时结果为:");
System.out.println("c = "+ c);
System.out.println("b = "+ b);}}