Skip to content

Commit b7da6d0

Browse files
Merge pull request codemistic#553 from rai-m47/main
Added code to check whether Kth bit is Set or Not.
2 parents fcbafd7 + 39cfc9e commit b7da6d0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.*;
2+
3+
public class KthBitSet {
4+
public static void main(String[] args) {
5+
Scanner sc= new Scanner(System.in);
6+
int n=sc.nextInt(),k= sc.nextInt();
7+
/*Method 1 using left shift operator*/
8+
if((n & (1<<(k-1))) == 0 )
9+
System.out.println("NO");
10+
else
11+
System.out.println("YES");
12+
13+
/*Method 2 using right shift operator*/
14+
// if(((n>>(k-1))&1) != 0)
15+
// System.out.println("YES");
16+
// else
17+
// System.out.println("NO");
18+
}
19+
}

0 commit comments

Comments
 (0)