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
Explanation:
No answer description is available. Let's discuss.
Discussion:
24 comments Page 1 of 3.

Dhananjay said:   6 years ago
int a=8,b=2; printf("%d",a>>b); explain.

Kanagaraj said:   10 years ago
Any one can explain simple masking program?

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.

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.

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.

@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 ;

What is difference between logical and bitwise OR?