On Tue, Aug 24, 2010 at 11:06 AM, Richard Quadling <rquadl...@gmail.com> wrote:
> On 20 August 2010 17:00, Andy McKenzie <amckenz...@gmail.com> wrote:
>>  Thanks to everyone who responded.  I've dealt with binary math
>> before, but it never occurred to me (and doesn't seem to be anywhere
>> in the document page at php.net!) that it would automatically pad the
>> number I entered.
> There is no padding.
> php -r "echo decbin(~2), PHP_EOL, decbin(-3);"
> 11111111111111111111111111111101
> 11111111111111111111111111111101
> That's 100% correct and proper. Not "padded".
> The example in [1] regarding E_ALL & ~E_NOTICE is a perfect example.
> Richard.
> [1] http://docs.php.net/manual/en/language.operators.bitwise.php
> --
> Richard Quadling.

If I feed it "10" and it assumes "00000000000000000000000000000011",
it's padding the number with zeros.

>From your example, this would have shown me what I needed to know:

"Then taking the value of E_NOTICE...
... and inverting it via ~:

As it was, I assumed the 32-bit number was there because the author
wanted it there, not because PHP assumes those extra bits.  As other
people have said, it probably would have been obvious if I'd known
more about how the system dealt with binary numbers, but coming from
my background, it wasn't at all obvious.  Not a big deal, and I can
work with it now that I know what's going on, but it would have taken
me a long time to figure it out on my own, if I ever had.  The tests I
was doing probably would have led me to the right answer eventually,
but Colin's original answer gave me the explanation and the solution
much faster.


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

Reply via email to