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.

Yugandhar said:   1 decade ago
@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 ;

Vanitha said:   1 decade ago
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.
(2)

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.

Vijay makhijani said:   1 decade ago
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.

Rajendra Acharya said:   1 decade ago
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.

Swapna said:   1 decade ago
|| 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.

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

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

Bujji said:   1 decade ago
This answer is wright because "|"this operator is called OR. It is a particular turning operator.

Datta said:   1 decade ago
Logical OR ||

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


Bitwise OR |

Ex: result = a | b;


Post your comments here:

Your comments will be displayed after verification.