php - Javascript 和 PHP 类似的函数给出不同的输出

标签 php javascript

<?
    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/

相关文章:

javascript - 添加一个点以扩展多边形而不将其附加到 Google map 中?

javascript - NodeJS 删除 API

javascript - check for this.length into a function 是什么意思?

php continue 跳过条件评估

php - 初学者 : php and mysql table issue

php - 在另一个表 PHP 中按列排序

javascript - 地理位置 : Is there are way to find if someone is going up in the altitude

javascript - 调整谷歌地图大小不起作用并且需要很长时间

PHP 警告 : redis. 所以: undefined symbol :第 0 行未知中的 php_json_decode_ex

php - 如何添加我的代码检查第三人而不是用户和管理员,如图所示