# 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?

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.

Ex : 1|0 = 1.

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

Ex : 1||1 = 1.

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.

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.

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.

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 ;

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 ;

Khushboo said:
1 decade ago

What is difference between logical and bitwise OR?

Bujji said:
1 decade ago

This answer is wright because "|"this operator is called OR. It is a particular turning operator.

Suni said:
1 decade ago

What is difference between logical and bitwise OR?

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.

Post your comments here:

Your comments will be displayed after verification.

Quick links

Quantitative Aptitude

Verbal (English)

Reasoning

Programming

Interview

Placement Papers

© IndiaBIX™ Technologies