谁能解释为什么下面的程序打印输出为 7
公开课测试{
public static void main(String []args){
int i =1;
int j =2;
int k= 5;
System.out.println(i|j|k);
}
我想知道 OR 运算在 java int 中是如何发生的。
最佳答案
那是bitwise-OR operator in Java .为简单起见,最后 8 位:
1 = 00000001
2 = 00000010
5 = 00000101
============
7 = 00000111 // 1 where the corresponding bit is set in any of the above numbers
关于java - 整数或运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18881127/