C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Yes / No Questions (Q.No. 1)
1.
Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
Yes
No
Explanation:
No answer description is available. Let's discuss.
Discussion:
8 comments Page 1 of 1.

Pavan sai said:   6 years ago
Here, the mask value is nothing but a number which is used to convert the given bits into the required way.

Let us take above example 11100111 is mask value.

Let us take another example, if we want to turn off the third bit from the rightmost of number 10011100 then;

10011100 &
11111011
--------------
10011000
----------
Here the mask value is 11111011.

Manoj said:   9 years ago

Why just change the mask value.

But we can't turnoff leftmost bit & 3rd bit from right here without using ~ operator.

We can turn off one or more bits in a number using bitwise & no need of ~ operator.

For example, Let a number 10011100

Now we want to turn its 4th nd 5th bit off, then we can do dis using & operator as

10011100 &
11100111
--------------
10000100
--------------

So in result 4th nd 5th bit are turned off.