It is a simple program to find out if an integer is a power of 4, but I couldn't understand this section when we take integer 255 & 256:
$x = $n;
while ($x % 4 == 0) {
$x /= 4;
}
if($x == 1)
Can someone explain it to me?
<?php
function is_Power_of_four($n)
{
$x = $n;
while ($x % 4 == 0) {
$x /= 4;
}
if($x == 1)
{
return "$n is power of 4";
}
else
{
return "$n is not power of 4";
}
}
print_r(is_Power_of_four(4)."\n");
print_r(is_Power_of_four(255)."\n");
print_r(is_Power_of_four(256)."\n");
?>