I'm converting some VB code to PHP, and in one line there is a logic operator AND.
The PHP and VB are giving me different results, so breaking down each step, it boils down to the logic operator AND, or && as it is in PHP.
In PHP I have:
($intAscii && $a)
with values of $intAscii = 87
and $a = 128
.
The above logic should return 0, but PHP returns 1.
Converting these to binary:
87 = 01010111
128 = 10000000
so it seems obvious this should return 0, so why does PHP insist on returning 1?
Full function here:
Function IsBitSet($intAscii , $intBit) {
//'change the value of the integer passed by
//'turning on the bit passed
$a=(int)(pow(2 ,(int)$intBit));
$b=($intAscii && $a);
echo '</br>Manual AND 87 && 128 '.(87 && 128) .'</br>';
echo 'is bit set $intAscii='.$intAscii .' $a='.$a.' And = '.( $b).'</br>';
Return(($intAscii && $a) <> 0);
}
and the output:
Manual AND 87 && 128 1
is bit set $intAscii=84 $a=128 And = 1