Which Bitwise Operator is Suitable for Turning on a Particular Bit in a Number?
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Which bitwise operator is suitable for turning on a particular bit in a number?
- && operator
- & operator
- || operator
- | operator
Answer: D. | operator
The | bitwise operator is suitable for turning on the bit in a number.
Solution
OR (|) bitwise operator is suitable for turning on a particular bit in a number. To arrive at the solution, we can clearly eliminate options A and C as they represent logical AND and logical OR operations, respectively. Now option B is bitwise AND (&), it cannot be used to turn on a particular bit in a number because if the input bit is 0, the bitwise AND will return 0 as the output. On the other hand, if bitwise OR is used, even if the input bit is set to 0, it will activate the output.
☛ Related Questions: