C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - General Questions (Q.No. 3)
3.
Which bitwise operator is suitable for turning on a particular bit in a number?
&& operator
& operator
|| operator
| operator
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
24 comments Page 1 of 3.

Samanth said:   2 decades ago
Can you tellme how?

Namo said:   2 decades ago
"|" this operator is known as OR operator
and
we know that with or operator
1| 0 = 1
1| 1 = 1
that's why here we use or operator

Deepshikha said:   1 decade ago
Namo is correct.

Slave of the eternal said:   1 decade ago
Well said namo.

Anji said:   1 decade ago
Why you did't think like this?

1& 0=0.

1& 1=1.

Join2piyush said:   1 decade ago
Anji here you take input as 1 & we want output 1 i.e. on.

But when our input is 0 & we want output as 1 I. E. On.

At that time if we & with 1 or & with 0 output will be always 0.

That's why we hav 2 use | to on the bit.

Parul said:   1 decade ago
Nano is absolutely correct. My doubt is clear now.

Rupa said:   1 decade ago
But when 0|0=0 so how to turn on this?

Amrendra said:   1 decade ago
@Rupa:.

If input is 0, you have to use 1 i.e. 0|1=1.

Vijay Arora said:   1 decade ago
Best use of the & operator is to check whether a particular bit od an operand is ON or OFF.

Why, we are not using &. ?


Post your comments here:

Your comments will be displayed after verification.