You are here: Re: What's wrong with this « All PHP « IT news, forums, messages
Re: What's wrong with this

Posted by www.j2be.com on 02/10/07 23:58

> 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?

Because you are using the strings and the result are related to the ascii
values.
try this

<?php
$apm = 9;
echo "APM = " . (string)$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<br>";
if ($apm & 256) echo "<br>256";
if ($apm & 512) echo "<br>512";
?>

In any case use the type cast to avoid problems
expecially for this kind of (and math) operations.

Regards.

L. A. Iarrusso

 

Navigation:

[Reply to this 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

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