Minimum Bit Flips
PHP
Hard
6 views
Problem Description
Input a and b. Print how many bit flips to turn a into b.
Input Format
One line: a b.
Output Format
One integer.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
[$a,$b]=array_map('intval',preg_split('/\\s+/', $inputText));
$x=$a ^ $b;
$c=0;
while($x>0){
$x &= ($x-1);
$c++;
}
echo $c;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!