C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - General Questions (Q.No. 2)
2.
Which bitwise operator is suitable for turning off a particular bit in a number?
&& operator
& operator
|| operator
! operator
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
41 comments Page 3 of 5.

Sateesh said:   8 years ago
I think whether in AND case both are true then only particle turned on. So I think OR case is the correct answer.

Anyone explain it.

Dinesh said:   1 decade ago
I explain in simple manner

bit wise & truth table
=========================
a b z
=========================
0 0 0
1 0 0
1 1 1
0 1 0
==========================
only one condition satisfyied foe on bit excpt bit value is off position

Heena said:   1 decade ago
Because && is a logical operator not a bitwise (bitwise is a operator that takes single bit at a time).

Suhas . u said:   1 decade ago
Which bit u want make 0 ...make only that bit 0 n allother bits 1...
ex:-to make 3rd bit 0 use &operator with one operand as11110111

Arjun Prasad said:   1 decade ago
~(1<<"bit position") is the operand

Arjun Prasad said:   1 decade ago
To make above operand you take a number 1 and then shift its only set bit to the number of the bit you want to turn off(1<<3) and then take AND with given number.

Sohan lal mits gwalior said:   1 decade ago
Bitwise 'AND' of any bit with zero bit is always zero (off).

Kumar said:   1 decade ago
Could anyone give an explanation in brief with example the above examples could not be understood

Sundar said:   1 decade ago
@Kumar

Let me explain.

How to turn off only the 4th bit (from right) in a 16-bit binary number?

unsigned int intFalg4Off = 0xfff7;
//Hex = 0xfff7 (or) Decimal = 65527 (or) Binay = 11111111 11110111

unsigned int intInputVal = 255;
//Decimal = 255 (or) 0x00ff (or) 00000000 11111111

unsigned int Result = intInputVal & intFalg4Off;

The result will be the & (AND operation) between the binary numbers given below :

11111111 11110111
00000000 11111111
00000000 11110111 (Decimal = 247 or Hex = 0x00f7)

Here 4th bit of the given input has been turned off. Therefore, intResult will contain the value 247.

Hope this will help you. Have a nice day!

Ramya said:   1 decade ago
Thanks sundar.


Post your comments here:

Your comments will be displayed after verification.