Kth Bit Check
Programming Interview
Medium
4 views
Problem Description
You're given {x}. Output 1 if k-th bit (0-based) of n is set, else 0.
Input Format
One line: n k.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if len(p)<2: sys.exit(0)
n=int(p[0]); k=int(p[1])
sys.stdout.write('1' if (n>>k)&1 else '0')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!