Skip to content

Commit 49aec74

Browse files
committed
3.2-Kth-bit-set-Video
1 parent 9f749cc commit 49aec74

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: Bit Manipulation/kth_bit_set_left_shift.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Problem : Check Kth bit is set or not
2+
# Method 1: Using Left Shift operator
3+
4+
n, k = [int (x) for x in input().split()]
5+
temp = 1 << (k - 1)
6+
if n & temp:
7+
print("SET")
8+
else:
9+
print("NOT SET")

Diff for: Bit Manipulation/kth_bit_set_right.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Problem : Check Kth bit is set or not
2+
# Method 1: Using Right Shift operator
3+
4+
n, k = [int (x) for x in input().split()]
5+
temp = n >> (k - 1)
6+
if temp and 1:
7+
print("SET")
8+
else:
9+
print("NOT SET")

0 commit comments

Comments
 (0)