17.位运算符
程序员文章站
2022-03-21 17:40:38
...
public class TestBitOperator {
public static void main(String[] args) {
int a = 3;
int b = 4;
System.out.println(a&b);
System.out.println(a|b);
System.out.println(a^b);
System.out.println(~b); //-4
//原0000...011 -3
//反0111...100
//补0111...101
//~
//原1000...010
//反1111...011
//补1000...100 -4
//移位
int c = 3<<2;
System.out.println(c);
System.out.println(12>>1);
}
}