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.

KIRAN said:   1 decade ago
What is unary operator?

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?

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.

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.

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.

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

Here no | option.

Only & option.

So answer B.

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

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

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.

ULLAS KULKARNI said:   1 decade ago
In detail,,
The key difference between & and && is ,its return value
EX; 1&2 returns zero whereas 1&&2 returns one ..
check out
1=0001 & 0010= 0000 on & opertion
and 1(true) and 2(true) so 1&& 2=1(true)


Post your comments here:

Your comments will be displayed after verification.