C Programming - Bitwise Operators - Discussion

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

Jansi said:   6 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)

Code:

#include<stdio.h>
void main()
{
int input = 171;
int check = 8; // 4th bit checker.

if(input & check)
printf("4th bit is set.");
else
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.