Re: Boolean type forced on string assignment inside if statement

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

 



2013/1/4 tamouse mailing lists <tamouse.lists@xxxxxxxxx>

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

Technically spoken they're comparing bits, whereas boolean operators does
the same, but treaten every value as a single bit.


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


-- 
github.com/KingCrunch

[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