Re: LONGINT... ? to be or not to be?...

From: Date: Tue, 28 Aug 2001 19:54:10 +0000
Subject: Re: LONGINT... ? to be or not to be?...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-64872@lists.php.net to get a copy of this message
A couple of points here... First, 0 is obviously wrong for 3221225472 & 1073741824 But I don't know how you got 2147483648 either. I get 1073741824 as 3221225472 = 11000000000000000000000000000000 1073741824 = 01000000000000000000000000000000 11000000000000000000000000000000 & 01000000000000000000000000000000 = 01000000000000000000000000000000 right? Anyways, to your question =P First, if you check here: http://www.php.net/manual/en/language.types.integer.php you will see that int's in PHP are always signed and that if they exceed the max size for an int they are converted to a float. Try running this on your server <?php $x = 3221225472; $y = 1073741824; echo "x = "; var_dump($x); echo "<BR>"; echo "y = "; var_dump($y); ?> I would be willing to bet that $x is a float and $y is an int, so the bitwise operator can't compare them. The only workaround I can offer you is this <?php $x = 3221225472; $y = 1073741824; $x = decbin($x); $y = decbin($y); $bitand = bindec($x & $y); echo "Bitwise and gives $bitand"; ?> It's a bit kludgy but it forces both $x and $y to be compared as binary numbers, which is what you want =) Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com ----- Original Message ----- From: "Alexey Prohorenko" <green@usa.dp.ua> To: <php-general@lists.php.net> Sent: Tuesday, August 28, 2001 1:47 PM Subject: [PHP] LONGINT... ? to be or not to be?... > Hello, > > I have one question. How can PHP work with longint (in C we call > them "unsigned long") variables? > F.e., I want to do next thing: > > 65536 & 4096 = 0 (this is right) > 65536 & 65536 = 65536 (again, everything is okay) > 196608 & 65536 = 65536 (perfect, it works great) > > but, > > 3221225472 & 1073741824 = 0 (this is wrong, right answer isn't 0 > but 2147483648) > > So, can anybody help me with this? Any suggestions? > > Thanks, anyway. Looking forward your answers. > Will check my mailbox every 5 minutes. :-) > > -- > green > [http://www.extrasy.net] > [http://www.unix-how-to.net] > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#64872) next »