I am using Windows XP + PHP 5.1.2 at home for development and using
Linux + PHP 4.4.2 at server side. In my code, I am doing some bitwise
operations. While doing this, I have come accross to different results
from my functions that uses bitwise xor (^) operator. When I digg into
the code, I have tried to print out the binary of a decimal number. The
result was so:
echo decbin(-5817441119);
// Prints 10100101010000001110010010100001 at local (PHP 5.1.2)
// Prints 10000000000000000000000000000000 at server (PHP 4.4.2)
Is this a bug? How can I workaround this problem? Thanks. 8 1313
Skeleton wrote: I am using Windows XP + PHP 5.1.2 at home for development and using Linux + PHP 4.4.2 at server side. In my code, I am doing some bitwise operations. While doing this, I have come accross to different results from my functions that uses bitwise xor (^) operator. When I digg into the code, I have tried to print out the binary of a decimal number. The result was so:
echo decbin(-5817441119); // Prints 10100101010000001110010010100001 at local (PHP 5.1.2) // Prints 10000000000000000000000000000000 at server (PHP 4.4.2)
Is this a bug? How can I workaround this problem? Thanks.
Hi,
Did you read the Fine Manual? http://nl2.php.net/manual/en/function.decbin.php
says:
string decbin ( int number )
----------------
Returns a string containing a binary representation of the given number
argument. The largest number that can be converted is 4294967295 in decimal
resulting to a string of 32 1's.
----------------
Your number is bigger, or actually smaller. ;-)
Read the usercontributed notes for details and solutions.
Regards,
Erwin Moller
Yes, I have read the manual and notes below the manual. But actually, I
don't need exactly the decbin function. I have used that just to show
something going wrong. My point is the ^ operator. For ex, look at the
following code and its outputs:
echo (1 ^ -5817441119);
// Prints -1522473824 which is true result, at PHP 5.1.2 + Windows
// Prints -2147483647 which is false result, at PHP 4.4.2 + Linux
I also thought that the reason is that the number is too small, but why
PHP 5 calculates correctly? Is there a big difference in number types
between PHP 4 and PHP 5? I don't know if it helps but when I checked
PHP_INT_MAX, it is 2147483647 for both.
Erwin Moller wrote: Skeleton wrote:
I am using Windows XP + PHP 5.1.2 at home for development and using Linux + PHP 4.4.2 at server side. In my code, I am doing some bitwise operations. While doing this, I have come accross to different results from my functions that uses bitwise xor (^) operator. When I digg into the code, I have tried to print out the binary of a decimal number. The result was so:
echo decbin(-5817441119); // Prints 10100101010000001110010010100001 at local (PHP 5.1.2) // Prints 10000000000000000000000000000000 at server (PHP 4.4.2)
Is this a bug? How can I workaround this problem? Thanks.
Hi,
Did you read the Fine Manual? http://nl2.php.net/manual/en/function.decbin.php
says: string decbin ( int number ) ---------------- Returns a string containing a binary representation of the given number argument. The largest number that can be converted is 4294967295 in decimal resulting to a string of 32 1's. ----------------
Your number is bigger, or actually smaller. ;-)
Read the usercontributed notes for details and solutions.
Regards, Erwin Moller
Skeleton wrote: Yes, I have read the manual and notes below the manual. But actually, I don't need exactly the decbin function. I have used that just to show something going wrong. My point is the ^ operator. For ex, look at the following code and its outputs:
echo (1 ^ -5817441119); // Prints -1522473824 which is true result, at PHP 5.1.2 + Windows // Prints -2147483647 which is false result, at PHP 4.4.2 + Linux
I also thought that the reason is that the number is too small, but why PHP 5 calculates correctly? Is there a big difference in number types between PHP 4 and PHP 5? I don't know if it helps but when I checked PHP_INT_MAX, it is 2147483647 for both.
Be careful of your base assumptions. php 5.1.2 on Linux produces
-2147483647 as well.
-david-
My PHP 5.1.2 is on Windows. So the problem is about the Operating
Systems.
David Haynes wrote: Be careful of your base assumptions. php 5.1.2 on Linux produces -2147483647 as well.
-david-
Skeleton wrote: My PHP 5.1.2 is on Windows. So the problem is about the Operating Systems.
No, the problem is that the number is outside of the defined bounds.
*Anything* could be the result, depending how that particular PHP
version, operating system or CPU treats overflowing numbers.
Ex falso quodlibet.
Bye!
Skeleton wrote: My PHP 5.1.2 is on Windows. So the problem is about the Operating Systems.
David Haynes wrote: Be careful of your base assumptions. php 5.1.2 on Linux produces -2147483647 as well.
-david-
No, it's difference is in the compiler. The operation you describe
causes a double-to-long-integer conversion overflow. Gcc probably
throws in a check which sets the value to the integer boundary whereas
MS Visual C just lets it wrap around.
So what should I do at this point? I need to make XOR operations with
such big(small) numbers.
Chung Leong wrote: Skeleton wrote: My PHP 5.1.2 is on Windows. So the problem is about the Operating Systems.
David Haynes wrote: Be careful of your base assumptions. php 5.1.2 on Linux produces -2147483647 as well.
-david-
No, it's difference is in the compiler. The operation you describe causes a double-to-long-integer conversion overflow. Gcc probably throws in a check which sets the value to the integer boundary whereas MS Visual C just lets it wrap around.
Skeleton wrote: So what should I do at this point? I need to make XOR operations with such big(small) numbers. Chung Leong wrote: Skeleton wrote: My PHP 5.1.2 is on Windows. So the problem is about the Operating Systems.
David Haynes wrote: > Be careful of your base assumptions. php 5.1.2 on Linux produces > -2147483647 as well. > > -david-
No, it's difference is in the compiler. The operation you describe causes a double-to-long-integer conversion overflow. Gcc probably throws in a check which sets the value to the integer boundary whereas MS Visual C just lets it wrap around.
What exactly are you trying to do? One possible solution is to perform
the operation on strings instead:
<?
$a = "\x01\x02\x03";
$b = "\xFF\x02\x03";
$c = $a ^ $b;
for($i = 0; $i < strlen($c); $i++) {
printf("%x, ", ord($c[$i]));
}
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sami Viitanen |
last post by:
Hello,
How can I check if a file is binary or text?
There was some easy way but I forgot it..
Thanks in adv.
|
by: Alexander |
last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without
SP1.
An i get this Error:
System.Runtime.Serialization.SerializationException:
Possible Version mismatch. Type...
|
by: Scott Langham |
last post by:
Hi, can anybody help please!
I've got an app with a few dlls. When I run the app I get the following
message in a message box:
The procedure entry point...
|
by: romixnews |
last post by:
Hi,
I'm facing the problem of analyzing a memory allocation dynamic and
object creation dynamics of a very big C++ application with a goal of
optimizing its performance and eventually also...
|
by: Michael Maes |
last post by:
Hi,
We have an ERP-Application that needs to interact with an "external
accountancy program". This is acchieved through a "Connector" (ActiveX-dll)
so kindly provided by the Accountancy-Program....
|
by: cantatahost |
last post by:
Hello,
Likely this has been asked before...
We have a library (in DLL form) that we distribute. The interface to the
library is all C, but within the library it uses C++ in many places.
...
|
by: Hongbo |
last post by:
Hi,
I use System.Security.Cryptography.HashAlgorithm.ComputeHash() method
with SHA512 to encrypt password.
I recently upgrade my website from .Net 1.1 to .Net 2.0. The passwords stop working....
|
by: JoeC |
last post by:
I am trying to create a windows program that reads binary graphics as
a resource. This has nothing to do with win32 but conversion of data
with memcpy.
graphic::graphic(UINT uiResID, HINSTANCE...
|
by: aznimah |
last post by:
hi, i'm work on image comparison. i'm using the similarity measurement which i need to:
1) convert the image into the binary form since the algorithm that i've use works with binary data for the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |