binary and & vs &=

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Is there any difference between doing:

\$var & 0x80;

and

\$var &= 0x80;

I've seen the second, using the &= in production code, but on my local
machine it errors out. Any thoughts?

Re: binary and & vs &=

doesn't not effect the value of \$var.

assigns the result of (\$var & 0x80) to \$var.

what error message are you getting?

Re: binary and & vs &=

cal

On it's own, the error would be a notice that \$var is undefined.
-- =

Rik Wasmus

Re: binary and & vs &=

that's all i could figure too...so i had to ask.

Re: binary and & vs &=

\$var &= 0x80  <=>  \$var = \$var & 0x80

Re: binary and & vs &=

perhaps <=> is a non-standard equality to the op. you mean that both
accomplish the same thing...they are just two different ways of writing the
same thing, right?

Re: binary and & vs &=

In math, <=> means "is equivalent to".

Re: binary and & vs &=

right. however, i was considering the question posed by the op...dealing
with hex and bits. he's probably not going to immediately see that you're
saying they're equal.

no big.

Re: binary and & vs &=

Thanks for the help the &= and & is clear to me now. I wasn't getting
an error, it just didn't echo out any value from the &= when I set the
\$var to an int value. Thanks again.

Re: binary and & vs &=

When people say "Don't do top posts", it means that you should write