Re: Boolean type forced on string assignment inside if statement
| From: | Andreas Perstinger | Date: | Thu, 03 Jan 2013 19:43:48 +0000 |
| Subject: | Re: Boolean type forced on string assignment inside if statement | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320017@lists.php.net to get a copy of this message | ||
Volmar Machado <qi.volmar@gmail.com> wrote:
>When the one of the operators were 2, the cases with "<------------"
>returns 2 otherwise returns 0 (Or 1 when any operator is 1). And if
>the operators are 1 and 2, return 0 too. Its curious for me.
& is the bitwise and operator. You have to look at the binary
representation of the numbers to see what is happening:
2 decimal is 0010 binary
1 decimal is 0001 binary
2 & 1 == 0010 & 0001 == 0000 == 0
In your other examples you had
2 & 3 == 0010 & 0011 == 0010 == 2
and
4 & 3 == 0100 & 0011 == 0000 == 0
Does this help?
Bye, Andreas