Re: Different binary results with different PHP versions



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

.



Relevant Pages

  • Re: string operation??
    ... string, but on a character in that string. ... generate trap representations, for example, ... I'm not completely certain that bitwise operators count ...
    (comp.lang.c)
  • what kind of function arguments iis this ??
    ... Sumit wrote: ... bits and asks for the bitwise OR of those two bits. ... Now, suppose you were to take a string of, say, eight ... We can say that four of those tiny switches are on ...
    (comp.lang.c)
  • Re: string concatenation
    ... but only in BAD VB6. ... And: bitwise and ... >> String first before performing the Addition. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Binary representation of a double?
    ... The binary representation of a double is, in fact: ... The first bit of the mantissa is omitted and is always 1 for normalized numbers. ... because we cannot simply use a bitwise shift operator to ...
    (microsoft.public.dotnet.framework)
  • Re: Binary representation of a double?
    ... The binary representation of a double is, in fact: ... The first bit of the mantissa is omitted and is always 1 for normalized numbers. ... | kind of unfortunate, because we cannot simply use a bitwise shift operator to ...
    (microsoft.public.dotnet.framework)