C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - True / False Questions (Q.No. 5)
Bitwise & can be used to check if a bit in number is set or not.
Answer: Option
No answer description is available. Let's discuss.
3 comments Page 1 of 1.

Jansi said:   5 years ago
Can anyone explain this answer? Please.

Sundar said:   1 decade ago
Assume that we have to check whether the 4th bit (from-right-side) of the given number is set or not.

Given Input: 171( Its 16-bit binary = 00000000 10101011)
Checker Data: 8 (Only 4th bit is on = 00000000 00001000)


void main()
int input = 171;
int check = 8; // 4th bit checker.

if(input & check)
printf("4th bit is set.");
printf("4th bit is NOT set.");

//output: 4th bit is set.

Hope this will help you. Have a nice day.

Aaradhana said:   1 decade ago
Can anyone explain how?

Post your comments here:

Your comments will be displayed after verification.