-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path011-Bitwise-Operators.java
More file actions
64 lines (53 loc) · 2.17 KB
/
Copy path011-Bitwise-Operators.java
File metadata and controls
64 lines (53 loc) · 2.17 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* ============================================================================
* Program Name : Bitwise Operators
* File Name : 011-Bitwise-Operators.java
* Class Name : BitwiseOperators
*
* Description:
* This program demonstrates the use of bitwise operators in Java.
* Bitwise operators perform operations directly on the binary
* representation of integer values.
*
* Bitwise Operators:
* & Bitwise AND
* | Bitwise OR
* ^ Bitwise XOR
* ~ Bitwise Complement
* << Left Shift
* >> Right Shift
*
* Objective:
* - Understand bitwise operators in Java.
* - Learn how bitwise operations work on binary values.
* - Display the result of each bitwise operation.
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
public class BitwiseOperators {
// The main() method is the entry point of every Java application.
public static void main(String[] args) {
// Declare and initialize the first integer variable.
int number1 = 10; // Binary: 1010
// Declare and initialize the second integer variable.
int number2 = 6; // Binary: 0110
// Print the values of both numbers.
System.out.println("First Number : " + number1); // Output: 10
System.out.println("Second Number : " + number2); // Output: 6
// Perform Bitwise AND operation.
System.out.println("number1 & number2 : " + (number1 & number2)); // Output: 2
// Perform Bitwise OR operation.
System.out.println("number1 | number2 : " + (number1 | number2)); // Output: 14
// Perform Bitwise XOR operation.
System.out.println("number1 ^ number2 : " + (number1 ^ number2)); // Output: 12
// Perform Bitwise Complement operation.
System.out.println("~number1 : " + (~number1)); // Output: -11
// Perform Left Shift operation.
System.out.println("number1 << 2 : " + (number1 << 2)); // Output: 40
// Perform Right Shift operation.
System.out.println("number1 >> 2 : " + (number1 >> 2)); // Output: 2
}
}