Re: Boolean type forced on string assignment inside if statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bit operators & and | are NOT and should NEVER be confused with
Logical operators && and ||:


<?php
/**
 * Bit operators in PHP
 */

$format = "Decimal: %2d  Binary: %4b\n";


$a = 4;
$b = 6;


echo "Variable \$a:\n";
printf($format, $a, $a);

echo "Variable \$b:\n";
printf($format, $b, $b);

$c = $a | $b;
echo "Result of OR bit operator\n";
printf($format, $c, $c);

$c = $a & $b;
echo "Result of AND bit operator\n";
printf($format, $c, $c);

?>


OUTPUT:
-------

Variable $a:
Decimal:  4  Binary:  100
Variable $b:
Decimal:  6  Binary:  110
Result of OR bit operator
Decimal:  6  Binary:  110
Result of AND bit operator
Decimal:  4  Binary:  100


Bit operators are not comparing values, they're COMBINING values.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux