JAVA: in the bitwise AND operator (&), bitwise OR operator (|), bitwise exclusive OR operator (^)

Bitwise AND operator (&)
Converted to binary--The same digits are all 1 , and the digit of the operation result is also 1.
If not at all, the corresponding digit of the operation result is 0

8 & 9

1000
1001
——
1000

Bitwise OR operator
Converted to binary-- If there is only one 1 for the same number of bits, the result of the operation will be 1 and
two 0s will be 0
8 | 9
1000
1001
——
1001

Bitwise exclusive OR operator
Converted to binary--If the number of digits is the same, it is 0 , and if it is different, it is 1
8 ^ 9
1000
1001
——
0001


public class Javabook {
    
    

	public static void main(String[] args) {
    
    
		int a = 8 & 9;
		int b = 8 | 9;
		int c = 8 ^ 9;
		System.out.println(a);
		System.out.println(b);
		System.out.println(c);
	}
}
输出:
8
9
1

Guess you like

Origin blog.csdn.net/weixin_42198265/article/details/114881016