C Programming - Bitwise Operators - Discussion

3. 

Which bitwise operator is suitable for turning on a particular bit in a number?

[A]. && operator
[B]. & operator
[C]. || operator
[D]. | operator

Answer: Option D

Explanation:

No answer description available for this question.

Samanth said: (Jun 10, 2010)  
Can you tellme how?

Namo said: (Aug 17, 2010)  
"|" 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: (Dec 7, 2010)  
Namo is correct.

Slave Of The Eternal said: (Feb 17, 2011)  
Well said namo.

Anji said: (Apr 6, 2011)  
Why you did't think like this?

1& 0=0.

1& 1=1.

Join2Piyush said: (Apr 21, 2011)  
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: (Jun 14, 2011)  
Nano is absolutely correct. My doubt is clear now.

Rupa said: (Jul 3, 2011)  
But when 0|0=0 so how to turn on this?

Amrendra said: (Aug 16, 2011)  
@Rupa:.

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

Vijay Arora said: (Aug 18, 2011)  
Best use of the & operator is to check whether a particular bit od an operand is ON or OFF.

Why, we are not using &. ?

Mansi said: (Aug 29, 2011)  
If | is OR operator than what do we call || operator as?

Swetha said: (Sep 14, 2011)  
@Namo

You are right and its easily understandable.

Viny said: (Sep 19, 2011)  
Namo is correct.

Datta said: (Oct 5, 2011)  
Logical OR ||

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


Bitwise OR |

Ex: result = a | b;

Swapna said: (Oct 13, 2011)  
|| it will call as logical OR.here OR truth table is true false=true, true true=true.so here OR operator is on a particular bit in a number.

Suni said: (Feb 21, 2012)  
What is difference between logical and bitwise OR?

Bujji said: (Mar 5, 2012)  
This answer is wright because "|"this operator is called OR. It is a particular turning operator.

Khushboo said: (Apr 4, 2012)  
What is difference between logical and bitwise OR?

Yugandhar said: (Jun 30, 2012)  
@Khushboo.

Logical OR operator is operated on two values that are True(T or 1) and False(F or 0)
i.e --(1)-- || --(2)--

(1),(2) are any expression that gives 0 or 1

Ex:

1||1=1
1||0=1
0||1=1
0||0=0

But if we see bit-wise OR operator ,it operated on any two integer values x,y.

Ex: x|y

In this every integer is represented by binary numbers, then OR operator is operated on each bit.

Ex:

10|6 gives 14 ; 10||6 gives 1
10 --> (1010) ; true || true =true
6 --> (0110) ;
---------------- ;
14 --> 1110 ;

Vijay Makhijani said: (Jul 31, 2012)  
As we know to turn on any state we need the output as 1.

We can easily get it if we use the OR (|) operator. As only a single 1 and all others as 0's would also result in the on state if we use the (|) operator.

Vanitha said: (Mar 19, 2013)  
Let me explain the answer.

The input value is 255 00000000 11111111

If we want to turn on the 10th bit means

The turn of value is 00000010 00000000

00000000 11111111
00000010 00000000 | operation
------------------
00000010 11111111
------------------

If we want to on particular bit OR operation is performed.

Rajendra Acharya said: (Nov 13, 2013)  
In bitwise operator we are comparing in between 2 digits.

Ex : 1|0 = 1.

But in logical operator we are comparing in between two conditions/ 2 values.

Ex : 1||1 = 1.

Kanagaraj said: (Aug 6, 2014)  
Any one can explain simple masking program?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.