java编写程序计算 整数 23、19 两个数的按位逻辑运算(即 与、或、非、异或)运算,并显示结果。
时间: 2023-05-18 14:03:29 浏览: 78
好的,以下是您所需的 Java 代码:
public class BitwiseOperators {
public static void main(String[] args) {
int num1 = 23;
int num2 = 19;
// Bitwise AND
int resultAnd = num1 & num2;
System.out.println("Bitwise AND: " + resultAnd);
// Bitwise OR
int resultOr = num1 | num2;
System.out.println("Bitwise OR: " + resultOr);
// Bitwise NOT
int resultNot1 = ~num1;
int resultNot2 = ~num2;
System.out.println("Bitwise NOT of " + num1 + ": " + resultNot1);
System.out.println("Bitwise NOT of " + num2 + ": " + resultNot2);
// Bitwise XOR
int resultXor = num1 ^ num2;
System.out.println("Bitwise XOR: " + resultXor);
}
}
输出结果如下:
Bitwise AND: 19
Bitwise OR: 23
Bitwise NOT of 23: -24
Bitwise NOT of 19: -20
Bitwise XOR: 6
阅读全文