Re: Re: Bitwise NOT operator?

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

 



On Wed, Aug 25, 2010 at 9:46 AM, Colin Guthrie <gmane@xxxxxxxxxxxxxx> wrote:
> 'Twas brillig, and Andy McKenzie at 24/08/10 21:42 did gyre and gimble:
>> Even if I'd thought about it in terms of the architecture, I
>> would have assumed that PHP would treat a two-bit number as a two-bit
>> number
>
> You two-bit hustler!
>
> In all seriousness tho', where do you ever provide a two bit number?
>
> $n = 2;
>
> The above is a number, it's not implicitly a two bit number...
>
> I mean, if I do:
>
> $n = 2;
> $n += 2;
>
> What do I get then? $n == 0? That's what *should* happen if $n was
> indeed two bits. It would overflow and wrap around.
>
> Your number in $n is in fact represented by whatever the variable type
> is. In this case it's a 32 bit integer number.
>
> Col
>

You're right, of course:  internally, PHP has to treat every number as
being some specific number of bits.  My point was that, not knowing a
lot about the low-level systems and internals, it's easy to assume
that something I enter as two bits (or three, or four, or whatever)
will be treated as such and returned as such.

My background isn't computer architecture:  what little relevant
experience I've had was two years in an electrical engineering program
(I decided it wasn't for me, and got out), but I never looked at
computer system architecture.  Based on my background, I tend to think
of a string of bits as just that -- a string of bits, basically
disconnected from anything else.  Therefore, if I feed five bits into
a NOT gate, I should get five bits back, and they should be the
opposite of what I fed it.  ~(10110) = 01001.  What I do with it after
that is up to me.  Math is different, and may require adding extra
bits, but a NOT isn't a mathematical function in my mind, it's a
function performed one bit at a time on exactly what you feed it.

As Gary points out, there ARE languages and places where that's doable
-- I've used the bit-field tool he mentioned, I think, although it was
a long time ago in that EE program -- so I had some reason for my
(incorrect) assumption.

However:  As Peter says, this is all fairly pointless, and totally
unnecessary on this list.  Colin gave me a meaningful answer in his
first response, and we've strayed pretty far from the topic.  At this
point, I'm not going to convince anyone of my view, and no one else is
going to convince me more than they have of their view, so let's let
the thread die in peace.  If other people want to continue the
discussion, go for it, but I'm going to try to keep quiet. 8-)

Thanks again to everyone who chimed in, though -- I appreciate the help.

-Alex McKenzie

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



[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