java 里的逻辑运算符,与(&)或(|)非(~)和异或(^)
来源:互联网 发布:大智慧软件 编辑:程序博客网 时间:2024/05/23 23:41
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 =111and2 =1or1 =111or2 =1not =111xor1 =111xor2 =1and = 1andresult =1or = 7orresutl =111not = -8notresult =11111111111111111111111111111000xor = 6xorresult =110最大:2147483647最小:-2147483648最大:1111111111111111111111111111111最大:31最小:10000000000000000000000000000000最小:32
在&和|运算中,如果两边是表达式则需要计算两边的值,
在&&和||运算中,则左边为假或者真就不再计算右边的值。
阅读全文
0 0
- java 里的逻辑运算符,与(&)或(|)非(~)和异或(^)
- 逻辑运算符与(&)、或(|)、非(!)、异或(^)及双与(&&)和双或(||)
- 逻辑运算符与或非(基础学习)
- C语言里的与(&)或(|)非(~)异或(^)和移位运算符(<<,>>)
- 逻辑运算(逻辑非,逻辑与,逻辑或,逻辑异或)
- nginx: if逻辑运算 (与或非) 实现
- C语言通过逻辑运算(与或非)实现加法
- java运算符(与,或,非,异或)
- 逻辑运算符与或非
- 与、或、非 异或 基本逻辑运算
- JavaScript中的逻辑运算的返回值(逻辑与&&,逻辑或||,逻辑非!)
- (转)JavaScript中的逻辑运算的返回值(逻辑与&&,逻辑或||,逻辑非!)
- Java 位运算(与、或、非、异或)
- 逻辑运算 或,与,非
- 逻辑运算“与或非”
- Java的位运算符:与(&)、非(~)、或(|)、异或(^)
- Java的按位运算符--&(与)、|(或)、^(异或)、~(非)
- Java的位运算符详解实例-与(&)、非(~)、或(|)、异或(^)
- (CSU
- session的生命周期
- 关于硬盘和分区的知识总结
- web级mysql
- Ubuntu14.04 下安装pip和virtualenv的方法
- java 里的逻辑运算符,与(&)或(|)非(~)和异或(^)
- 医学图像数据库
- error:Cannot add or update a child row: a foreign key constraint fails (`xx库`.`xx表`,
- HTTP协议--简单认识TCP/IP
- java super继承测试
- isbn号码
- TCP/UDP/IP分片
- 正则表达式 字符转义
- Java多线程