Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

Javascript and PHP's similar function gave different output

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

Output in screen (by PHP:)

int64 Object ( [h] => -1725854399 [l] => -393 ) 

Output in console (by Javascript) (Correct one):

int64 { h=-1725854399, l=1020051063}

I am trying to correct this whole day. but couldn't. What modification do I need in PHP code to get the answer as javascript?

I Want to get javascript output using php

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You used a >>> operator in JavaScript. It means logical rightshift. PHP Does not have this, this is the error.

To get the same output:

Change the operator in JavaScript from '>>>' to '>>' or

implement a logical rightshift function in PHP.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...