37-32 >= 0 so change the number to 5 (which is what is left over)
5 - 16 < 0, so ignore
5 - 8 < 0, so ignore
5 - 4 >= 0, so change the number to 1 (which is what is left over)
1 - 2 < 0, so ignore
1 - 1 >= 0, so change the number to 0
PHP Code:
$num = 64;
for ($i=6; $i>0; $i--)
{
$result = pow(2, $i);
if ($num & $result)
{
echo 1;
}
else
{
echo 0;
}
}
outputs 100000 (same thing as what i just posted really)