Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

PHP Can't convert hex over 7fffffff ?

In php, you can seamlessly convert strings representing both decimal and hex numbers to integers using 0 + string.

An (int) cast does not do this, and other methods gave me problems. Anyway:

print '<p>';

$hx = "0x2345e";

$n = 0 + $hx;

print "$n <br>";

$hx = "0xcb623";

$n = 0 + $hx;

print "$n <br>";

$hx = "0xcb511df6";

$n = 0 + $hx;

print "$n </p>";

Expected output:

144478

833059

-883876362

(or a large positive number).

Actual output:

144478

833059

0

Doing intval($hx,16); returns 2147483647 which is 0x7fffffff.

How to deal with hex strings representing numbers >0x7fffffff ?

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    0x7FFFFFFF is the maximum value for a 32-bit signed integer.

    You will likely need to break the hex-string into two pieces and evaluate them separately if you want to deal with this problem.

Still have questions? Get your answers by asking now.