|
Posted by Mad Hatter on 02/10/07 23:37
Hi Folks
Okay, I know it's late and my brain is asleep but I just can't work out why
this doesn't work. I'm trying to work out what bits are on in a variable.
When I set the variable to, for example, 9, bits 8 and 1 should be set.
Anyway, here's the code:-
<?php
$apm = '9';
echo "APM = ".$apm."<br>";
if ($apm & '1') echo "<br>1";
if ($apm & '2') echo "<br>2";
if ($apm & '4') echo "<br>4";
if ($apm & '8') echo "<br>8";
if ($apm & '16') echo "<br>16";
if ($apm & '32') echo "<br>32";
if ($apm & '64') echo "<br>64";
if ($apm & '128') echo "<br>128";
if ($apm & '256') echo "<br>256";
if ($apm & '512') echo "<br>512";
And here's the result I'm getting:-
APM = 9
1
8
16
32
128
512
I can understand the 1 and 8 but why are 16,32,128 and 512 coming up?
Should I go to bed and look at it in the morning when no doubt everything
will be obvious?
Navigation:
[Reply to this message]
|