# RE: [PHP] Help needed with hexdec();

I spent many frustrating days debugging a similar problem.  I
don't understand exactly what is going on, but it seems that the
problems revolve around PHP's treatment of an integer as signed
or unsigned.

Through experimentation I determined that the way you specify an
integer constant (decimal or hex) with the sign bit on will
affect how PHP treats that integer.

Try the following: determine the signed decimal equivalents of
the two hex integers in your code & replace the hex
representations with the decimal "equivalents".  So, if I'm
remembering correctly (please check my math), the line

if (\$a > hexdec("ffffffff"))

would become

if (\$a > -1)

See if this makes a difference.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, July 06, 2002 5:54 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Help needed with hexdec();
>
>
> Hi Guys,
>
> I have a problem wich I hope has been solved by someone :-)
>
> Here's the deal,
>
> I have to convert a perl script to PHP trying to do so
> I get negative
> values from hexdec(), If I use (int)hexdec() the
> numbers aren't negative
> anymore, but they do not add up to what they should.
>
> Here's the perl line:
> \$a = FF (\$a, \$b, \$c, \$d, \$temparr[8],  \$S11, hex("698098d8"));
>
>
> this is PHP:
> \$a = FF (\$a, \$b, \$c, \$d, \$temparr[8],  \$S11,
> hexdec("698098d8"));
>
> FF is a function:
> function FF(\$a,\$b,\$c,\$d,\$x,\$s,\$ac)
> {
>          \$a += F(\$b,\$c,\$d) + \$x + \$ac;
>          if (\$a > hexdec("ffffffff"))
>                    {
>                    \$a = substr(\$a,strlen(\$a)-9,9) ;
>                    }
>          \$a = RL(\$a,\$s);
>          \$a += \$b;
>          return \$a;
> }
>
> F is also a function:
> function F(\$x, \$y, \$z)
> {
>          return (((\$x) & (\$y)) | ((~\$x) & (\$z)));
> }
>
> Could anybody tell me what I am missing here?
>
> e-mail:  <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
>
>

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