Re: Bitwise operation giving wrong results

From: Date: Thu, 30 Oct 2008 00:46:14 +0000
Subject: Re: Bitwise operation giving wrong results
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-282597@lists.php.net to get a copy of this message
Ashley Sheridan wrote:
On Wed, 2008-10-29 at 20:01 -0400, sean greenslade wrote:
I have the following code as a test: <?php $a = $_GET['a']; $b = $_GET['b']; echo $a . " & " . $b . " = "; $out = $a & $b; echo $out; //echo 15 & 2; ?> if I set a to 15 and b to 2 in the URL like so: test.php?a=15&b=2 it outputs zero as the answer. When I run the hard-coded '&' operation (the commented out echo), it returns 2. I'm stumped.
In PHP a boolean true also equates to 1. You are using the & operator though, instead of the && which I think you're looking for.
You misunderstand the question I think. He's trying to do this: http://www.php.net/manual/en/language.operators.bitwise.php For the OP: Try casting $a and $b to int's: $a = (int)$_GET['a']; no idea if it'll help though. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#282597) next »