RE: [PHP] Help needed with hexdec();
| From: | Jonathan Rosenberg | Date: | Sun, 07 Jul 2002 13:43:05 +0000 |
| Subject: | RE: [PHP] Help needed with hexdec(); | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105957@lists.php.net to get a copy of this message | ||
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: frank@hertogs.info [mailto:frank@hertogs.info]
> Sent: Saturday, July 06, 2002 5:54 PM
> To: php-general@lists.php.net
> 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:frank@hertogs.info> frank@hertogs.info
>
>