C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - General Questions (Q.No. 4)
4.
Which bitwise operator is suitable for checking whether a particular bit is on or off?
&& operator
& operator
|| operator
! operator
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
29 comments Page 2 of 3.

Joyeeta said:   1 decade ago
While doing bitwise operation, when we do 1&0, we get 0, means the bit is off. When we do 1&1, this proves that the bit is on.

Love shukla said:   1 decade ago
&& is a Logical operator which combine two or more relation
Ex: let a=5,b=2
(a==5)&& (b==2)
true && true = true
i.e, 1 && 1 = 1

While & is a bitwise operator which has ability to support the manipulation of data at bit level
Ex:let a=9,b=15
Then, a & b
9 & 15
1001 & 1111 = 1001 (use AND operation on each bit)
i.e, ans:- 9

Saikat Sinha Ray said:   1 decade ago
& is a bit wise operator that performs the AND operation of binary representation of given numbers.

Ex : 2 && 0 = 0 (In binary 0000 0010 & 0000 0000 = 00000 0000)

&& is a logical operator that matches between two condition

Ex : if(condition1 is true && condition2 is true)
................
else
................

Shritama said:   1 decade ago
x & 1 = x.
x | 0 = x.

Here no | option.

Only & option.

So answer B.

Anusha said:   1 decade ago
Yeah, & is the correct answer to turnoff the bit in a number.

The basic operations of & is :

0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1.

Bhavin said:   1 decade ago
In case & and | both options will be given in question. What will answer for this question?please give my answer.

Bit_ter said:   1 decade ago
@Bhavin the answer is & because,

0 | 1 =1
1 | 1 =1.

But,

0 & 1 =0
1 & 1 =1.

You can see that when you '&' a particular bit (0 or 1) with 1 then the output is the input.

Dimple said:   1 decade ago
Why we can't use the OR (|) operator instead of AND (&) for checking whether the bit is on or off?

KIRAN said:   1 decade ago
What is unary operator?

Ghanshyam Sharma said:   1 decade ago
I think that the right answer is D.

For eg:

If I write if(a) then it is 1.

If I write if(!a) then it is 0.


Post your comments here:

Your comments will be displayed after verification.