-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck bit.cpp
More file actions
46 lines (34 loc) · 790 Bytes
/
Check bit.cpp
File metadata and controls
46 lines (34 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
In a given integer N, check whether the ith bit is set or not.
Input Format
First and only line of input contains N and i.
Constraints
0 <= N <= 109
0 <= i <= 30
Output Format
Print "true" if ith bit is set in the given integer N, "false" otherwise.
Sample Input 0
10 1
Sample Output 0
true
Explanation 0
The binary form of 10 is: 1010. So the 1st bit in 10 is set. Note that LSB bit is referred as 0th bit.
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N,i;
int res;
cin>>N>>i;
res = (N >> (i));
if (res & 1)
printf("true\n");
else
printf("false\n");
return 0;
}