Re: [PHP] Bitwise AND for 31-st bit

2011-05-18 Thread Vitalii Demianets
On Tuesday 17 May 2011 22:06:34 David Harkness wrote: > It appears that PHP is truncating the constant 0x8000 to be within > MIN_INT and MAX_INT instead of as a bit field, but when shifting 1 << 31 it > doesn't do apply any constraints. That's pretty typical of > bit-manipulation: it will merri

Re: [PHP] Bitwise AND for 31-st bit

2011-05-17 Thread David Harkness
It appears that PHP is truncating the constant 0x8000 to be within MIN_INT and MAX_INT instead of as a bit field, but when shifting 1 << 31 it doesn't do apply any constraints. That's pretty typical of bit-manipulation: it will merrily slide 1 bits off either end. This explains why & produces 0

Re: [PHP] Bitwise AND for 31-st bit

2011-05-17 Thread Vitalii Demianets
On Tuesday 17 May 2011 18:31:00 Bálint Horváth wrote: > Hi, > Hmm.. interesting... > "tst1=-2147483648, tst1_eq=-2147483648, tst1_type=integer tst2=2147483648, > tst2_eq=-2147483648, tst2_type=double" at me... > PHP Version 5.3.3-1ubuntu9.5 (Apache 2.0 - i686) That is what I expected too. There ar

Re: [PHP] Bitwise AND for 31-st bit

2011-05-17 Thread Bálint Horváth
Hi, Hmm.. interesting... "tst1=-2147483648, tst1_eq=-2147483648, tst1_type=integer tst2=2147483648, tst2_eq=-2147483648, tst2_type=double" at me... PHP Version 5.3.3-1ubuntu9.5 (Apache 2.0 - i686) Valentine On Tue, May 17, 2011 at 5:19 PM, Vitalii Demianets wrote: > Hello, all! > > I've encounter

[PHP] Bitwise AND for 31-st bit

2011-05-17 Thread Vitalii Demianets
Hello, all! I've encountered odd behavior of PHP regarding bitwise AND operation when dealing with 31-st bit, and kindly ask to give me some pointers. Consider the following snippet: $tst1 = (1 << 31); $tst2 = 0x8000; $tst1_eq = $tst1 & 0x8000; $tst2_eq = $tst2 & 0x8000; print "tst1=

RE: [PHP] Bitwise NOT operator?

2010-08-25 Thread Bob McConnell
From: Richard Quadling > On 24 August 2010 21:42, Andy McKenzie wrote: >> On Tue, Aug 24, 2010 at 3:55 PM, Ford, Mike wrote: From: Andy McKenzie [mailto:amckenz...@gmail.com] >>> From your example, this would have shown me what I needed to know: "Then taking the value of E_NOT

Re: [PHP] Bitwise NOT operator?

2010-08-25 Thread Peter Lind
Please stop arguing this pointless topic on the php mailing list. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscr

Re: [PHP] Bitwise NOT operator?

2010-08-25 Thread Richard Quadling
On 24 August 2010 21:42, Andy McKenzie wrote: > On Tue, Aug 24, 2010 at 3:55 PM, Ford, Mike wrote: >>> -Original Message- >>> From: Andy McKenzie [mailto:amckenz...@gmail.com] >>> Sent: 24 August 2010 17:24 >>> To: php-general@lists.php.net >

Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Andy McKenzie
On Tue, Aug 24, 2010 at 3:55 PM, Ford, Mike wrote: >> -Original Message- >> From: Andy McKenzie [mailto:amckenz...@gmail.com] >> Sent: 24 August 2010 17:24 >> To: php-general@lists.php.net >> Subject: Re: [PHP] Bitwise NOT operator? > > >> From y

RE: [PHP] Bitwise NOT operator?

2010-08-24 Thread Ford, Mike
> -Original Message- > From: Andy McKenzie [mailto:amckenz...@gmail.com] > Sent: 24 August 2010 17:24 > To: php-general@lists.php.net > Subject: Re: [PHP] Bitwise NOT operator? > From your example, this would have shown me what I needed to know: > > "Then

Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Ashley Sheridan
On Tue, 2010-08-24 at 12:24 -0400, Andy McKenzie wrote: > On Tue, Aug 24, 2010 at 11:06 AM, Richard Quadling > wrote: > > On 20 August 2010 17:00, Andy McKenzie wrote: > >> Thanks to everyone who responded. I've dealt with binary math > >> before, but it never occurred to me (and doesn't seem

Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Andy McKenzie
On Tue, Aug 24, 2010 at 11:06 AM, Richard Quadling wrote: > On 20 August 2010 17:00, Andy McKenzie 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 a

Re: [PHP] Bitwise NOT operator?

2010-08-24 Thread Richard Quadling
On 20 August 2010 17:00, Andy McKenzie 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.

Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Andy McKenzie
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. The example I gave was essentially a test I was running: in the real scri

Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Peter Lind
On 20 August 2010 17:41, Peter Lind wrote: > On 20 August 2010 17:10, Andy McKenzie wrote: >> Hey everyone, >> >>  I'm really not sure what's going on here:  basically, the bitwise >> NOT operator seems to simply not work.  Here's an example of what I >> see. >> >> Script

Re: [PHP] Bitwise NOT operator?

2010-08-20 Thread Peter Lind
On 20 August 2010 17:10, Andy McKenzie wrote: > Hey everyone, > >  I'm really not sure what's going on here:  basically, the bitwise > NOT operator seems to simply not work.  Here's an example of what I > see. > > Script > > $ cat bintest2.php > > > $bin = 2; > $notbin = ~

[PHP] Bitwise NOT operator?

2010-08-20 Thread Andy McKenzie
Hey everyone, I'm really not sure what's going on here: basically, the bitwise NOT operator seems to simply not work. Here's an example of what I see. Script $ cat bintest2.php = Output $ php bintest2.php Bin: 1

Fwd: [PHP] Bitwise operation giving wrong results

2008-10-31 Thread sean greenslade
-- Forwarded message -- From: sean greenslade <[EMAIL PROTECTED]> Date: Fri, Oct 31, 2008 at 11:22 PM Subject: Re: [PHP] Bitwise operation giving wrong results To: Yeti <[EMAIL PROTECTED]> Cool, thanks. It worked. I didn't know you typeset PHP like that. On Thu

Re: [PHP] Bitwise operation giving wrong results

2008-10-30 Thread Yeti
Usually in PHP one does not take much care about the data types, but in this case you absoloodle have to. If you use bit operators on a character then its ascii number will be taken instead (how should a number based operation work with a string?) also if you pass on $_GET params directly into ay

Re: [PHP] Bitwise operation giving wrong results

2008-10-29 Thread Chris
Ashley Sheridan wrote: On Wed, 2008-10-29 at 20:01 -0400, sean greenslade wrote: I have the following code as a test: if I set a to 15 and b to 2 in the URL like so: test.php?a=15&b=2 it outputs zero as the answer. When I run the hard-coded '&' operation (the commented out echo), it returns

Re: [PHP] Bitwise operation giving wrong results

2008-10-29 Thread Ashley Sheridan
On Wed, 2008-10-29 at 20:01 -0400, sean greenslade wrote: > I have the following code as a test: > $a = $_GET['a']; > $b = $_GET['b']; > echo $a . " & " . $b . " = "; > $out = $a & $b; > echo $out; > //echo 15 & 2; > ?> > > if I set a to 15 and b to 2 in the URL like so: > > test.php?a=15&b=2 >

[PHP] Bitwise operation giving wrong results

2008-10-29 Thread sean greenslade
I have the following code as a test: if I set a to 15 and b to 2 in the URL like so: test.php?a=15&b=2 it outputs zero as the answer. When I run the hard-coded '&' operation (the commented out echo), it returns 2. I'm stumped. -- --Zootboy

Re: [PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-07 Thread Richard Lynch
On Tue, July 4, 2006 7:35 am, Mathijs wrote: > //Do if VALIDATE_CHECK1 is set BUT NOT when VALIDATE_CHECK3 is set. > if ($flag2 & self::VALIDATE_CHECK1 && $flag2 & ~self::VALIDATE_CHECK3) Did you check operator precedence for & versus &&? Perhaps you just need parentheses... I'm also not at all

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Mathijs
Jochem Maas wrote: Mathijs wrote: Jochem Maas wrote: Mathijs wrote: ... Thank you very much. This seems to work :). cool. heres's a couple of funcs that might help you to understand bitwise operations better: >= 1) { $x++; } return $i ? $j <<= $x: 0; } /* doesn't break when expone

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Mathijs
Jochem Maas wrote: Mathijs wrote: Jochem Maas wrote: Mathijs wrote: ... Thank you very much. This seems to work :). cool. heres's a couple of funcs that might help you to understand bitwise operations better: >= 1) { $x++; } return $i ? $j <<= $x: 0; } /* doesn't break when expone

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Mathijs
Jochem Maas wrote: Mathijs wrote: Jochem Maas wrote: Mathijs wrote: ... Thank you very much. This seems to work :). cool. heres's a couple of funcs that might help you to understand bitwise operations better: >= 1) { $x++; } return $i ? $j <<= $x: 0; } /* doesn't break when expone

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Mathijs
Jochem Maas wrote: Mathijs wrote: Jochem Maas wrote: Mathijs wrote: ... Thank you very much. This seems to work :). cool. heres's a couple of funcs that might help you to understand bitwise operations better: >= 1) { $x++; } return $i ? $j <<= $x: 0; } /* doesn't break when expone

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Jochem Maas
Mathijs wrote: > Jochem Maas wrote: >> Mathijs wrote: ... >>> > > > Thank you very much. > This seems to work :). cool. heres's a couple of funcs that might help you to understand bitwise operations better: >= 1) { $x++; } return $i ? $j <<= $x: 0; } /* doesn't break when exponents are

Re: [PHP] Bitwise operators and check if an bit is NOT within theflag.

2006-07-04 Thread Mathijs
Jochem Maas wrote: Mathijs wrote: Hello there. I am working with some bitwise Operators for validating some variables. Now i need to know if an certain bit is NOT set and an other bit IS set. Example. class Test { const VALIDATE_CHECK1 = 1; const VALIDATE_CHECK2 = 2; const VALIDATE_CHECK3 =

Re: [PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-04 Thread Jochem Maas
Mathijs wrote: > Hello there. > > I am working with some bitwise Operators for validating some variables. > Now i need to know if an certain bit is NOT set and an other bit IS set. > > Example. > > > const VALIDATE_CHECK1 = 1; > const VALIDATE_CHECK2 = 2; > const VALIDATE_CHECK3 = 4; > const V

[PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-04 Thread Mathijs
Hello there. I am working with some bitwise Operators for validating some variables. Now i need to know if an certain bit is NOT set and an other bit IS set. Example. This last example i can't seem to get to work. I Want to only do that when for example VALIDATE_CHECK3 is not within the $fla

Re: [PHP] Bitwise operators

2005-09-26 Thread cron
The second value is the number of spaces to shift, dint realize that. Thanks for your time Chris. Angelo - Original Message - From: "Chris Boget" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; Sent: Monday, September 26, 2005 2:02 PM Subject: Re: [PHP] Bi

Re: [PHP] Bitwise operators

2005-09-26 Thread Chris Boget
I tested; I don't want to waste peoples time. Rewriting the question: this outputs: c = 32 d = 0 The question is why? First row is the bit's number and the second row is the bit's value: #8 | #7 | #6 | #5 | #4 | #3 | #2 | #1 --- 128 | 64 | 32 | 16 | 8 |

Re: [PHP] Bitwise operators

2005-09-26 Thread cron
Angelo - Original Message - From: "Chris W. Parker" <[EMAIL PROTECTED]> To: Sent: Monday, September 26, 2005 1:28 PM Subject: RE: [PHP] Bitwise operators [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> on Monday, September 26, 2005 9:18 AM said: > So i

Re: [PHP] Bitwise operators

2005-09-26 Thread Robin Vickery
On 9/26/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > From php manual: > > $a << $b Shift leftShift the bits of $a $b steps to the left (each step > means "multiply by two") > $a >> $b Shift rightShift the bits of $a $b steps to the right (each step > means "divide by two") > > > So i ask what

RE: [PHP] Bitwise operators

2005-09-26 Thread Chris W. Parker
[EMAIL PROTECTED] on Monday, September 26, 2005 9:18 AM said: > So i ask what this output? > > $a = 4; > $b = 3; > > echo $a << $b; > echo $a >> $b; You just spent 3-5 minutes writing an email and now almost 10 minutes waiting for a reply to something that would

[PHP] Bitwise operators

2005-09-26 Thread cron
Hello, >From php manual: $a << $b Shift leftShift the bits of $a $b steps to the left (each step means "multiply by two") $a >> $b Shift rightShift the bits of $a $b steps to the right (each step means "divide by two") So i ask what this output? $a = 4; $b = 3; echo $a << $b; echo $a >> $b;

Re: [PHP] Bitwise operations criticism needed

2004-08-31 Thread Gerard Samuel
Marek Kilimajer wrote: Your checks are something like if($user['tom'] & $perm['read']) echo 'Tom can read'; Only the 3rd bit is checked, all others are ignored and won't do any harm. Anyway, the "clean" way of setting permissions is: $user['tom'] = $perm['execute'] | $perm['write'] | $perm['read'];

Re: [PHP] Bitwise operations criticism needed

2004-08-31 Thread Marek Kilimajer
Gerard Samuel wrote: Marek Kilimajer wrote: Gerard Samuel wrote: The situation. Im currently using a home brewed groups permission code in my site, but for limited users/groups its ok. Beyond that, the code will take the fast road to hell. I started to look in depth at bitwise operations today, a

Re: [PHP] Bitwise operations criticism needed

2004-08-31 Thread Gerard Samuel
Marek Kilimajer wrote: Gerard Samuel wrote: The situation. Im currently using a home brewed groups permission code in my site, but for limited users/groups its ok. Beyond that, the code will take the fast road to hell. I started to look in depth at bitwise operations today, and after much googlin

Re: [PHP] Bitwise operations criticism needed

2004-08-31 Thread Marek Kilimajer
Gerard Samuel wrote: The situation. Im currently using a home brewed groups permission code in my site, but for limited users/groups its ok. Beyond that, the code will take the fast road to hell. I started to look in depth at bitwise operations today, and after much googling, and looking at other

[PHP] Bitwise operations criticism needed

2004-08-31 Thread Gerard Samuel
The situation. Im currently using a home brewed groups permission code in my site, but for limited users/groups its ok. Beyond that, the code will take the fast road to hell. I started to look in depth at bitwise operations today, and after much googling, and looking at other code, came up with t

Re: [PHP] Bitwise flagging in mysql database

2003-06-10 Thread Jason Wong
On Tuesday 10 June 2003 06:08, Mike Mannakee wrote: > I have a script that is collecting a bunch of information, and storing this > in a database. However, the rows are kinda big and I'm thinking of packing > the information into flag bits, and storing this information in one string > in the datab

[PHP] Bitwise flagging in mysql database

2003-06-09 Thread Mike Mannakee
I have a script that is collecting a bunch of information, and storing this in a database. However, the rows are kinda big and I'm thinking of packing the information into flag bits, and storing this information in one string in the database. I'm wondering if I should use mysql's bitwise operator

[PHP] Bitwise operator question

2003-03-03 Thread Dan Sabo
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 perm

[PHP] bitwise AND is acting strange

2001-07-22 Thread Jeremy
The users on my website all have an "access" number that is used to give them access to different parts of the site. Each bit represents a different part of the site. So, if a user has an access of 10, which is 1010 in binary, they have access to the parts of the site that are represented by the s

[PHP] bitwise comparison

2001-05-18 Thread nick
How can I store a large number, value over 8 billion for bitwise comparison? I have a large set of switchs, getting up to 2 pow 34, and it goes outside the size of an int, can't set a type that will work. Nicholas Burke Strategic Profits Inc. -- PHP General Mailing List (http://www.php.net/

RE: [PHP] Bitwise solution?

2001-03-02 Thread Boget, Chris
> > I have 2 values. The first is a constant while the second is not. > Is the first value a numerical value (real/integer?) or a > string value? String. This is what I've come up with and it seems to work pretty ok. What do you guys think? (test code to illustrate a point; other than the XOR

Re: [PHP] Bitwise solution?

2001-03-02 Thread Christian Reiniger
On Thursday 01 March 2001 20:58, you wrote: > But that would give me a value of a variable variable. > And I need a numerical value so > > $var1 ="joe"; > $var2 = date( "U" ); > > echo "$var1$var2"; > > won't do me any good. Ahhh. You want to use the mcrypt functions or simply crypt() ? -- Chr

Re: [PHP] Bitwise solution?

2001-03-01 Thread Harshdeep S Jawanda
Hi, "Boget, Chris" wrote: > I have 2 values. The first is a constant while the second is not. Is the first value a numerical value (real/integer?) or a string value? If it is numerical, then one of the things you could do for using a numerical value of (say) less than 100 could be: $finalVar

RE: [PHP] Bitwise solution?

2001-03-01 Thread Boget, Chris
> on 3/1/01 02:34 PM, [EMAIL PROTECTED] split open and melted thusly: > > I was thinking I could do something like this: > > ( var1 & var2 ) > i think what you want is: > ${$var1$var2} But that would give me a value of a variable variable. And I need a numerical value so $var1 ="joe"; $var2 = da

[PHP] Bitwise solution?

2001-03-01 Thread Boget, Chris
I'm wondering how I can do the following (if it is possible at all): I have 2 values. The first is a constant while the second is not. The second value, in this case, is a unix time stamp and as such will change every time it is set, down to the second. I need to somehow merge the two values s