Closed Thread
Results 1 to 3 of 3

Thread: Bit Wise JavaScript and PHP

  1. #1
    MrGamma is offline Learning Programmer
    Join Date
    Jul 2008
    Posts
    50
    Rep Power
    13

    Bit Wise JavaScript and PHP

    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?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Bit Wise JavaScript and PHP

    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    MrGamma is offline Learning Programmer
    Join Date
    Jul 2008
    Posts
    50
    Rep Power
    13

    Re: Bit Wise JavaScript and PHP

    Never mind... JavaScript was using unsigned integers while Php was using Signed...

    At least I think that's what was happening... This fixed it...

    Code:
    function _unSign($i1) {
        if(0x7fffffff < $i1) {
            $i1 -= 0xffffffff + 1.0;
        }elseif (-0x80000000 > $i1) {
            $i1 += 0xffffffff + 1.0;
        }
        return $i1;
    }
    _unSign(1532515508) ^ _unSign(-3955803181) = 1332703079

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with Javascript
    By Soupturkey in forum JavaScript and CSS
    Replies: 2
    Last Post: 05-16-2010, 03:16 AM
  2. javascript help
    By -Hurricane- in forum JavaScript and CSS
    Replies: 3
    Last Post: 05-06-2010, 06:53 AM
  3. JavaScript
    By Bannana97 in forum JavaScript and CSS
    Replies: 5
    Last Post: 02-19-2009, 03:54 AM
  4. Bit Wise JavaScript and PHP
    By MrGamma in forum C# Programming
    Replies: 1
    Last Post: 10-31-2008, 01:05 PM
  5. Javascript
    By seal in forum JavaScript and CSS
    Replies: 1
    Last Post: 06-22-2007, 12:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts