<?
class int64{
var $h;
var $l;
function int64($h, $l)
{
$this->h = $h;
$this->l = $l;
}
}
function int64rrot(int64 $dst, int64 $x, $shift)
{
$dst->l = ($x->l >> $shift) | ($x->h << (32-$shift));
$dst->h = ($x->h >> $shift) | ($x->l << (32-$shift));
print_r($dst);
}
$a = new int64(1779033703,-205731576);
$b = new int64(1779033701,-205731572);
int64rrot($a,$b,19);
?>
<script type="text/javascript">
function int64rrot(dst, x, shift)
{
dst.l = (x.l >>> shift) | (x.h << (32-shift));
dst.h = (x.h >>> shift) | (x.l << (32-shift));
console.log(dst);
}
function int64(h, l)
{
this.h = h;
this.l = l;
}
a = new int64(1779033703,-205731576);
b = new int64(1779033701,-205731572);
int64rrot(a,b,19);
</script>
屏幕输出(由 PHP 实现:)
int64 Object ( [h] => -1725854399 [l] => -393 )
控制台中的输出(通过 Javascript)(正确的一个):
int64 { h=-1725854399, l=1020051063}
我一整天都在努力纠正这一点。但不能。我需要对 PHP 代码进行哪些修改才能获得 JavaScript 答案?
I Want to get javascript output using php
最佳答案
您在 JavaScript 中使用了 >>> 运算符。它的意思是逻辑右移。 PHP没有这个,这是错误。
要获得相同的输出:
将 JavaScript 中的运算符从“>>>”更改为“>>”或
在 PHP 中实现逻辑右移函数。
关于php - Javascript 和 PHP 类似的函数给出不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13029288/