Re: [PHP] Re: Bitwise NOT operator?

2010-08-25 Thread Andy McKenzie
On Wed, Aug 25, 2010 at 9:46 AM, Colin Guthrie gm...@colin.guthr.ie 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



RE: [PHP] RE: Bitwise operator question

2003-03-03 Thread Dan Sabo
Thanks Philip,

OK I understand the binary thing but that line, I just don't see it, It's
not the or operator that's summing up the two binary values is it?

Dan

-Original Message-
From: Philip Hallstrom [mailto:[EMAIL PROTECTED]
Sent: Monday, March 03, 2003 3:53 PM
To: Dan Sabo
Cc: [EMAIL PROTECTED]
Subject: [PHP] RE: Bitwise operator question


Yes.  Oops.

-philip

On Mon, 3 Mar 2003, Dan Sabo wrote:

 Hi Phillip,

 Don't U mean

   0001
 | 0100
 = 0101

 ?

 Dan

 -Original Message-
 From: Philip Hallstrom [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 03, 2003 2:33 PM
 To: Dan Sabo
 Cc: [EMAIL PROTECTED]
 Subject: Re: Bitwise operator question


 Here's how I think about it...

 CREATE_RECORDS = 1 in decimal and 0001 in binary.
 ALTER_RECORDS = 4 in decimal and 0101 in binary.

 that line returns a binary string where *any* of the bits are 1, so line
 them up:

0001
 |  0101
 =  0101

 which is 5.

 On Mon, 3 Mar 2003, Dan Sabo wrote:

  Hi,
 
  I'm reading the description of Bitwise Operators on page 81 of
 Professional
  PHP 4, the Wrox book.  In the highlighted example on that page, the
line
 of
  code...
 
  $user_permissions = CREATE_RECORDS | ALTER_RECORDS;
 
  the description in the book says that this line is building a set of
user
  permissions out of the previously created constants with the OR operator
 (I
  understand what OR means).  The value of $user_permissions is set to
 either
  1 or 4, which is in fact 5 (0101).  But how is this single line doing
 that?
  The explanation was cryptic (to me).
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


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


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



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



Re: [PHP] Re: Bitwise

2001-11-19 Thread David Robley

On Tue, 20 Nov 2001 13:12, Fred wrote:
 OK, it seems as though I was on the right track.  I cast the variables
 as integers and all is well.  Thanks to Rasmus and his msg:
 http://www.phpbuilder.com/mail/php-developer-list/199901/0485.php

 A question remains: why are variables that are initially set to numbers
 not cast as integers?

 According to the manual variables are initially cast as integers if
 they are created with an assignment to an integer number.  While this
 is the case with variables assigned in code (i.e. $One = 16) it appears
 not to be the case with GET variables passed via the URL.

Anything coming via get/post is a string, regardless of what it looks 
like :-).

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   This is the Netherlands, Tom stated flatly.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: Bitwise

2001-11-19 Thread Fred


 Anything coming via get/post is a string, regardless of what it looks
 like :-).

That is the conclusion I have drawn.  However, the variables are
automatically transformed based on the context in which they are used.
Mathmatic operators and functions work flawlessly with numbers passed via
GET without the need for casting.  That is just not the case with the
bitwise operators.

Fred



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]