Page 1 of 1
[RESOLVED] PHP: IF-statments: One ampersand
Posted: Wed Jul 15, 2009 12:24 pm
by spider.nick
I need some help wrapping my head around this. I did not write this code, so I am trying to understand why the User Access Control [UAC] is working the way it is.
When the check
is run, it returns false. When
is run, it returns true.
Any help is greatly appreciated.
Nick
Re: PHP: IF-statments: One ampersand
Posted: Wed Jul 15, 2009 12:38 pm
by turbolemon
It's all about bitwise operators:
Code: Select all
$a & $b
And
Bits that are set in both $a and $b are set.
If you know binary, 1 & 127 is true because 00000001 = binary 1 and 01111111 = binary 127, and all the set bits (8th 1) are set in binary 127, whereas binary 16 = 00010000, therefore the 8th bit set in binary 1 is not set in binary 16. A quite efficient way to store this information, a single byte

.
Re: PHP: IF-statments: One ampersand
Posted: Wed Jul 15, 2009 12:42 pm
by spider.nick
turbolemon wrote:It's all about bitwise operators:
Code: Select all
$a & $b
And
Bits that are set in both $a and $b are set.
If you know binary, 1 & 127 is true because 00000001 = binary 1 and 01111111 = binary 127, and all the set bits (8th 1) are set in binary 127, whereas binary 16 = 00010000, therefore the 8th bit set in binary 1 is not set in binary 16. A quite efficient way to store this information, a single byte

.
I was trying to comprehend it as binary; however, I was having issues pin-pointing exactly
how it was being figured. Thank you for the prompt explanation!
Nick