Explain the Various Types of Bitwise Operators in Java.
Advertisements
Question
Explain the Various Types of Bitwise Operators in Java.
Explain
Advertisements
Solution
- Bitwise AND Operator (
&): This operator compares the corresponding bits of two operands and returns1only when both bits are1. Otherwise, it returns0. - Bitwise OR Operator (
|): This operator compares the corresponding bits of two operands and returns1if at least one of the bits is1. Otherwise, it returns0. - Bitwise XOR Operator (
^): This operator compares the corresponding bits of two operands and returns1when the bits are different. If both bits are the same, it returns0. - Bitwise Complement Operator (
~): This is a unary operator that reverses all the bits of an integer value. It changes0to1and1to0. - Left Shift Operator (
<<): This operator shifts the bits of a number to the left by the specified number of positions. Zeros are inserted into the vacant positions on the right. - Signed Right Shift Operator (
>>): This operator shifts the bits of a number to the right by the specified number of positions while preserving its sign. - Unsigned Right Shift Operator (
>>>): This operator shifts the bits of a number to the right by the specified number of positions and fills the vacant positions on the left with zeros.
shaalaa.com
Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]
