-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwise_Operation.java
More file actions
30 lines (21 loc) · 942 Bytes
/
Bitwise_Operation.java
File metadata and controls
30 lines (21 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class Bitwise{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first integer: ");
int a = scanner.nextInt();
System.out.print("Enter the second integer: ");
int b = scanner.nextInt();
int and = a & b;
int or = a | b;
int xor = a ^ b;
System.out.println("\nResults:");
System.out.println("Bitwise AND:");
System.out.println(a + " & " + b + " = " + and + " (binary: " + Integer.toBinaryString(and) + ")");
System.out.println("Bitwise OR:");
System.out.println(a + " | " + b + " = " + or + " (binary: " + Integer.toBinaryString(or) + ")");
System.out.println("Bitwise XOR:");
System.out.println(a + " ^ " + b + " = " + xor + " (binary: " + Integer.toBinaryString(xor) + ")");
scanner.close();
}
}