There was an error while loading. Please reload this page.
2 parents fcbafd7 + 39cfc9e commit b7da6d0Copy full SHA for b7da6d0
Java/FiveBitManipulation/KthBitSet.java
@@ -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