Write a PHP program to check if the bits of the two given positions of a number are same or not.
112 - > 01110000Test 2nd and 3rd positionResult: TrueTest 4th and 5th positionResult: False
<?php function test_bit_position($num, $pos1, $pos2) { $pos1--; $pos2--; $bin_num = strrev(decbin($num)); if ($bin_num[$pos1] == $bin_num[$pos2]) { return "true"; } else { return "false"; } } echo test_bit_position(112,5,6)."\n"; ?>
Sample Output:
true
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer