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