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?
Discussion:
29 comments Page 3 of 3.
Ajendra Singh said:
1 decade ago
Relation operator is used to make an expression to compound one whereas bitwise and is used to operate on bits for faster access.
Payal said:
1 decade ago
&& is a relational operator it compare two values.
Whereas & is logical operator.
Whereas & is logical operator.
Riya said:
1 decade ago
What is the difference between && and & ?
Seenu said:
1 decade ago
Hi! Guys this is a simple one. Let consider 8-bit binary number,
Binary(8 bit) = 0000 1100
suppose we want check 3rd bit is on or off(on=1 & off=0), just like this,
0000 1100 (Decimal=12)
&
0000 0100 (Decimal=4,we are checking 3rd bit so it is 1)
----------
0000 0100 (Decimal=4)
----------
If we got some value then checking bit is on,otherwise off.
In C language,
if(12&4)
print("The third bit is on");
else
print("The third bit is off");
Binary(8 bit) = 0000 1100
suppose we want check 3rd bit is on or off(on=1 & off=0), just like this,
0000 1100 (Decimal=12)
&
0000 0100 (Decimal=4,we are checking 3rd bit so it is 1)
----------
0000 0100 (Decimal=4)
----------
If we got some value then checking bit is on,otherwise off.
In C language,
if(12&4)
print("The third bit is on");
else
print("The third bit is off");
Amit(saktimaan) said:
1 decade ago
I don't understand this.
Siraj said:
1 decade ago
Hey anybody can explain me how & operatoer is used to chek on or off ?
Madhureddy said:
1 decade ago
Hai frndz. How & operator is used to check whether a bit is on or off is as follows let us conceive that there is a binary num 10101000 if you want to check third bit is on or off then perform and operation to 00001000 then if 3rd bit is 1 its on else its turned off.
Here if wana check nth bit make n-1 bit as 1 remaining as 0. Then perform and operation then you will know the answer.
Here if wana check nth bit make n-1 bit as 1 remaining as 0. Then perform and operation then you will know the answer.
HARSHIT BHATIA said:
1 decade ago
Yaa, & operator is perfect for find out on or off.
Kishore said:
1 decade ago
As we know that truth table of AND is if 2 number is true then only output becomes true. For that reason & is used to find bits on or off.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers