Trying to convert a javascript file to php, I've run into a bit of a problem.
<script type="text/javascript">
function TryXOR()
{
var a = -5664999325;
var b = 195920;
a ^= b;
document.write(a);
}
TryXOR();
</script>
<?php $a = -5664999325; $b = 195920; $a ^= $b; echo "<br>$a<br>";?>
In JS, I get a result of -1370225357. This is the result I want. In PHP, though, I get -2147287728. Anyone care to help me out?
Edit: It appears that if I set 'a' in PHP to 5664999325, it returns 1370225357. I'm confused. Why does JS ignore the signed value and then re-apply it?
Edit #2: Using -915899570 for 'a' and 345042 for 'b' returns -915588964 for JS (and VB, and normal php XOR), and -915588960 for my modified PHP xor. This is just driving me mad. What the hell's wrong with PHP?
Bitwise xor relies pretty heavily on the size of the datatype you are using as well as its numeric representation. I'm pretty sure - though not certain, as I'm really tired - that your problem has to do with with one of those two things. In short, unsigned/signed problem
I just need PHP to mimic JS. How can I tell PHP to handle it as...whatever JS handles it as?
pack
yes, that might work.
Doesn't matter, I gave up on the project. If anyone was wondering, it was going to be a php script to display the Google page rank of any page you gave it...
Apparently, the script listed here can do that:
http://talk.iwebtool.com/thread2082.html
*shrug*
Doesn't work correctly on my server... It's the same code I had converted from javascript, but without the URL behind it.