Check Nth Bit
PHP
Medium
5 views
Problem Description
Input n and k (0-based). Print 1 if kth bit is set, else 0.
Input Format
One line: n k.
Output Format
One integer 0/1.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$n,$k]=array_map('intval',preg_split('/\\s+/', $inputText));
echo (($n>>$k)&1);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!