-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion2.txt
More file actions
31 lines (23 loc) · 1012 Bytes
/
Question2.txt
File metadata and controls
31 lines (23 loc) · 1012 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
Check weather K-th bit is set or not.
Given a number N and a bit number K, check if Kth index bit of N is set or not. A bit is set if it is 1.
Position of set bit '1' should be indexed starting with 0 from LSB side in binary representation of the number.
Note - Index is starting from 0.
Example-1
Input : N = 4 , K = 0
Output : No
Explanation: Binary representation of 4 is 100, in which 0th index bit from LSB is not set.
So, return false.
Example-2
Input : N = 4 , K = 2
Output : Yes
Explanation: Binary representation of 4 is 100, in which 2nd index bit from LSB is set.
So, return true.
Example-3
Input : N = 500 , K = 3
Output : No
Explanation: Binary representation of 500 is 111110100, in which 3rd index bit from LSB is not set.
So, return false.
Your task:
You don't have to read input or print anything. Your task is to complete the
function checkKthbit() that takes n and k as parameters and returns either true(if kth bit is set)
or false (if kth bit is not set).