0

I'm trying to some mathematics in PHP to decrypt a server's bytes, but I cannot seem to use integers exactly the same way I can in Java. Here's an example.

echo intval(-690939880 * 134775813);

This current example prints out -2092836736. This value is almost correct. In Java, however, it outputs the value I want.

System.out.println(-690939880 * 134775813);

The value outputted here is -2092836744. How can I replicate this equation in PHP so that it works?

I want the value to overflow, like above.

baseman101
  • 352
  • 1
  • 4
  • 19
  • 2
    Those aren't `double`s in your Java example, they're `int`s. – azurefrog Sep 12 '14 at 03:17
  • Fixed. Sorry, it's late. I forgot to also mention that outputting the float values in Java will result in the same answer in PHP, since PHP uses floats. I tested doubles in Java as well, and doubles seem to work fine. That's why I'm asking. – baseman101 Sep 12 '14 at 03:20

1 Answers1

0

I have fixed the issue. It took a bit of searching for hours, but I found the solution on StackOverflow.

<?php
echo int32Val(-690939880 * 134775813);
//outputs -2092836744

function int32Val($value) {
    if ($value < -2147483648)
        return -(-($value) & 0xffffffff);
    elseif ($value > 2147483647)
        return ($value & 0xffffffff);
    return $value;
}
?>

Answer: Force PHP integer overflow

Community
  • 1
  • 1
baseman101
  • 352
  • 1
  • 4
  • 19