programming-examples/php/Basics/PHP program to reverse the bits of an integer (32 bits unsigned)..php
2019-11-18 14:44:36 +01:00

15 lines
266 B
PHP

<?php
function reverse_integer($n)
{
$result = 0;
for($i= 0; $i<32; $i++)
{
$result <<= 1;
$result|= ($n & 1);
$n >>= 1;
}
return $result;
}
print_r(reverse_integer(1234)."\n");
?>