Thursday, January 9, 2025
HomeComputer ScienceBitwise Operator in Java

Bitwise Operator in Java

Bitwise Operators in Java are used to perform operations on binary representations of integers. These operators work at the bit level and include:

  1. AND (&): Performs a bitwise AND.
    Example: 5 & 3 results in 1.
  2. OR (|): Performs a bitwise OR.
    Example: 5 | 3 results in 7.
  3. XOR (^): Performs a bitwise exclusive OR.
    Example: 5 ^ 3 results in 6.
  4. NOT (~): Performs a bitwise complement (inverts bits).
    Example: ~5 results in -6.
  5. Left Shift (<<): Shifts bits to the left, adding zeros on the right.
    Example: 5 << 2 results in 20.
  6. Right Shift (>>): Shifts bits to the right, preserving the sign bit.
    Example: 5 >> 1 results in 2.
  7. Unsigned Right Shift (>>>): Shifts bits to the right, filling zeros irrespective of the sign.
    Example: -5 >>> 1 results in 2147483645.
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x