package com.wei.bace.operator;
public class Demo05 {
public static void main(String[] args) {
//与(and) 或(or) 非(取反)。
boolean a =true;
boolean b =false;
System.out.println("a && b:"+(a&&b));//逻辑与运算
System.out.println("a || b:"+(a||b));//逻辑或运算
System.out.println("!(a&&b):"+!(a&&b));//逻辑非运算 如果是假则为真;
//短路运算
int c= 5;
boolean d = (c<4)&&(c++<4);//c=5不小于4 &&指令执行不下去 故而false d=false c=5
System.out.println(c);//5
System.out.println(d);//false
// 位运算/二进制
/*
A = 0011 1100
B = 0000 1101
A&B =0000 1100 位 与指令
A/B =0011 1101 位 或指令
A^B =0011 0001 位 异或指令
~B =1111 0010 位 取反
~A =1100 0011 位 取反
2*8=16 2*2*2*2=16
>>右移
<<左移
0000 0000 =0
0000 0001 =1
0000 0010 =2
0000 0011 =3
0000 0100 =4 ****
0000 0101 =5
0000 0110 =6
0000 0111 =7
0000 1000 =8 ***
0000 1001 =9
0000 1010 =10
0000 1011 =11
0000 1100 =12
0000 1101 =13
0000 1110 =14
0000 1111 =15
0001 0000 =16 ***
*/
System.out.println(2<<8 );//512
System.out.println(2<<4 );//32
System.out.println(2<<5 );//64
System.out.println(2<<9 );//1024
System.out.println(16>>4 );//1
System.out.println(16>>2 );//4
}
}