Kth Bit Check
Python
Medium
3 views
Problem Description
Read two non-negative integers n and k. 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!