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 2 of 5.

Nkandu said:   10 years ago
I am new to c programming I don't understand it can someone please help me.

Apshana said:   1 decade ago
Why && will not be answer? And tell me what is the difference between & and &&?

Sudha said:   1 decade ago
And operator follow a multiple mechanism. So Zero the position will be off, the OR operator addition mechanism.

Mallikarjun said:   1 decade ago
Bitwise & is used for masking bits i.e 1 can be done 0.

Ranjana said:   1 decade ago
Any bit AND(&) with 0 will give a zero .i.e. will turn that particular bit OFF.

Ajarmani said:   1 decade ago
@Sudheer.

The basics of bitwise operation is:
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0

1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0

Using this we will solve an example.

5 & 3
1.Convert to binary
101 & 011.

2. Now apply bitwise operation:
1 0 1 = 5
& & &
0 1 1 = 3
_____
0 0 1 = 1

Hence 5 & 3 = 1.

Kannan P said:   1 decade ago
Given 4 option A and C not a bit-wise operator. B and D is a bit-wise operator. If you use D it will totally changed the values in high to low and low to high. But use & operator mask bit. We can change where ever you want.

Sudheer said:   1 decade ago
Hai friends I am new to C language programming I am unable to understand the logics in this languages in bitwise operation can any explain this in simple way please?

Umesh said:   1 decade ago
How to convert hexadecimal into binary?

Answer:

1) Take the hexa decimal no. and calculate it decimal value first.

2) Convert decimal number into binary having 4 digit.

3) Repeat 1 and 2 until number is not end.

e.g.

A2F for A decimal is 10.

and 10 = 1010 in binary in the same way.
2 = 2 in decimal and in binary 0010.
F = 15 in decimal and in binary 1111.

So Hexa(A2F) = Binary (1010 0010 1111).

Prema Latha.S said:   1 decade ago
Bitwise AND operator (&), one's complement operator(~)

Example: To unset the 4th bit of byte_data or to turn off a particular bit in a number.

Explanation: Consider, Material from Interview Mantra. Subscribe to free updates via email.

char byte_data= 0b00010111;byte_data= (byte_data)&(~(1<<4));

1 can be represented in binary as 0b00000001 = (1<<4)

<< is a left bit shift operator,

It shifts the bit 1 by 4 places towards left.

(1<<4) becomes 0b00010000

And ~ is the one's complement operator in C language.

So ~(1<<4) = complement of 0b00010000

= 0b11101111

Replacing value of byte_data and ~(1<<4) in (byte_data)&(~(1<<4));

We get (0b00010111) & (0b11101111)

Perform AND operation to below bytes.

00010111

11101111

-----------

00000111

-----------

Thus the 4th bit is unset.
(1)


Post your comments here:

Your comments will be displayed after verification.