Bitwise operators in Java are fundamental to low-level programming, enabling bit-by-bit manipulation of integers. They are binary operators that operate on bits, providing operations like AND, OR, XOR, and NOT, among others. Mastery of these operators helps enhance code efficiency, particularly in algorithms dealing with bits and bytes.

The Java programming language provides six types of bitwise operators. Let's delve into each, explaining their function and providing illustrative examples.

Binary Operators
Binary operators work on two operands - binary AND (&), OR (|), XOR (^), Left Shift (<<), and Right Shift (>>).

Here are examples of these operators:
Bitwise AND (&)

The '&' operator performs AND on bits of two integers. The result is 1 only if both bits are 1.
Example: ``` int a = 60, b = 13, c = 0; c = a & b; System.out.println(c); // Outputs 12 ``` This example uses the bitwise AND operator. The binary representation of 60 is '0011 1100' and for 13, it's '0000 1101'. So, the result '0000 1100' is 12.
Bitwise OR (|)

The '|' operator performs OR on bits of two integers. The result is 1 if any of the two bits is 1.
Example: ``` int a = 60, b = 13, c = 0; c = a | b; System.out.println(c); // Outputs 61 ``` Here, the binary representation of 60 is '0011 1100' and for 13, it's '0000 1101'. The result '0011 1101' is 61.
Unary Operator

Unary operators perform operation on single operand - Bitwise NOT (~), Unary Plus (+), and Unary Minus (-).
Bitwise NOT (~)







![[2020] - Web Technologies - Java Script - Operators Bitwise operators Practice](https://i.pinimg.com/originals/e5/61/8d/e5618d5e7e3a7a66cb55c5efb11b1649.jpg)












The '~' operator inverts all the bits in an integer, effectively adding one to the two's complement of the number.
Example: ``` int a = 60, b; b = ~a; System.out.println(b); // Outputs -61 ``` Here, '~60' signifies that all bits should be inverted, logically making it '-61'.
Remember, bitwise operators cast float or double numbers to int before using them as bitwise operators.
Shift Operators
Shift operators move bits of the number towards the left or right.
Left Shift (<<)
Shifts the bits of the number to the left.
Example: ``` int a = 60, b; b = a << 2; System.out.println(b); // Outputs 240 ``` This example shifts '60' to the left by 2 positions, resulting in '240'.
Right Shift (>>)
Shifts the bits of the number to the right.
Example: ``` int a = 60, b; b = a >> 2; System.out.println(b); // Outputs 15 ``` Here, '60' is shifted to the right by 2 positions, resulting in '15'.
Understanding bitwise operators empowers you to delve into system programming, enhance algorithmic efficiency, and aids in understanding low-level functioning of computer systems. Keep exploring and practicing to master these operators!