I'm having an issue trying to figure out why in javascript.
1532515508 ^ -3955803181 = 1332703079
but in php it equals...
1532515508 ^ -3955803181 = -614968140
Does anybody know why?
Bit Wise JavaScript and PHP
Started by MrGamma, Oct 31 2008 11:50 AM
2 replies to this topic
#1
Posted 31 October 2008 - 11:50 AM
|
|
|
#2
Posted 31 October 2008 - 12:05 PM
It depends on the number of bits used to represent those values. If they are using a different number of bits, you will get different results.
#3
Posted 31 October 2008 - 12:09 PM
Never mind... JavaScript was using unsigned integers while Php was using Signed...
At least I think that's what was happening... This fixed it...
_unSign(1532515508) ^ _unSign(-3955803181) = 1332703079
At least I think that's what was happening... This fixed it...
function _unSign($i1) {
if(0x7fffffff < $i1) {
$i1 -= 0xffffffff + 1.0;
}elseif (-0x80000000 > $i1) {
$i1 += 0xffffffff + 1.0;
}
return $i1;
}
_unSign(1532515508) ^ _unSign(-3955803181) = 1332703079


Sign In
Create Account


Back to top









