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 2 of 3.

Datta said:   1 decade ago
Logical OR ||

Ex: if(a || b) { ... }


Bitwise OR |

Ex: result = a | b;

Viny said:   1 decade ago
Namo is correct.

Swetha said:   1 decade ago
@Namo

You are right and its easily understandable.

Mansi said:   1 decade ago
If | is OR operator than what do we call || operator as?

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 &. ?

Amrendra said:   1 decade ago
@Rupa:.

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

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

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

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.

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

1& 0=0.

1& 1=1.


Post your comments here:

Your comments will be displayed after verification.