package tablejava;
public class AndOr2 {
public static void main(String[] args) {
int and1=7;
int and2=1;
int or1=7;
int or2=1;
int not=7;
int xor1=7;
int xor2=1;
System.out.println("and1 ="+Integer.toBinaryString(and1));
System.out.println("and2 ="+Integer.toBinaryString(and2));
System.out.println("or1 ="+Integer.toBinaryString(or1));
System.out.println("or2 ="+Integer.toBinaryString(or2));
System.out.println("not ="+Integer.toBinaryString(not));
System.out.println("xor1 ="+Integer.toBinaryString(xor1));
System.out.println("xor2 ="+Integer.toBinaryString(xor2));
int andresult=and1&and2;
System.out.println("and = "+andresult);
System.out.println("andresult ="+Integer.toBinaryString(andresult));
int orresutl=or1|or2;
System.out.println("or = "+orresutl);
System.out.println("orresutl ="+Integer.toBinaryString(orresutl));
int notresult=~not;
System.out.println("not = "+notresult);
System.out.println("notresult ="+Integer.toBinaryString(notresult));
int xorresult=xor1^xor2;
System.out.println("xor = "+xorresult);
System.out.println("xorresult ="+Integer.toBinaryString(xorresult));
System.out.println("最大:" + Integer.MAX_VALUE);
System.out.println("最小:" + Integer.MIN_VALUE);
System.out.println("最大:" + Integer.toBinaryString(Integer.MAX_VALUE));
String str1=Integer.toBinaryString(Integer.MAX_VALUE);
System.out.println("最大:" + str1.length());
System.out.println("最小:" + Integer.toBinaryString(Integer.MIN_VALUE));
String str2=Integer.toBinaryString(Integer.MIN_VALUE);
System.out.println("最小:" + str2.length());
/*
* int的取值范围为(-2147483648~2147483647),占用4个字节(-2的31次方到2的31次方-1)
*
* */
}
}
and1 =111
and2 =1
or1 =111
or2 =1
not =111
xor1 =111
xor2 =1
and = 1
andresult =1
or = 7
orresutl =111
not = -8
notresult =11111111111111111111111111111000
xor = 6
xorresult =110
最大:2147483647
最小:-2147483648
最大:1111111111111111111111111111111
最大:31
最小:10000000000000000000000000000000
最小:32
在&和|运算中,如果两边是表达式则需要计算两边的值,
在&&和||运算中,则左边为假或者真就不再计算右边的值。