#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    2
    Rep Power
    0

    Question XOR Problem when converting from JavaScript to PHP


    hi,


    i want to convert a javascript programm to php an encountered the following problem:

    there is a part in the javascript file, where an XOR operation is performed by:

    [javascript:]
    t2=959077477;
    m=7127917138;
    x1 = t2 ^ m;
    alert(x1);
    -> resulting in: -1846460873

    (t2 and m are variables, i just used the values where the problem occures)

    when i convert this to php:
    [php:]
    $t2=959077477;
    $m=7127917138;
    $x1 = $t2 ^ $m;
    echo "<br>".$t2." XOR ".$m." = ".$x1;

    the result is: -959077478

    does anyone know why those 2 values are diffrent ?
    is there a problem with the length of the numbers (if yes how can i solve it)

    thanks,
    mike
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 1999
    Posts
    119
    Rep Power
    15
    I'm not a pro at this, but I'd say your problem is with the floating point precission of integers... those are large numbers you're throwing around, and when you raise one to the other, it's getting huge... Don't know how exactly to solve that...

    Perhaps look up a better algorithm using google?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    2
    Rep Power
    0
    thanks again on that one...

    i thought so myself.
    i used a different server an there it worked (it also did on my old test server back home).
    so i kinda solved the problem by avoiding it *g*

    mike

IMN logo majestic logo threadwatch logo seochat tools logo