Reply to What's wrong with this

Your name:

Reply:


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?

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация