1

When I try to perform bitwise XOR operation in php and js, they are producing different results in some cases , for example

2166136261 ^ 101 = -2128831072 on browsers (js)
2166136261 ^ 101  = 2166136224(php)

My understanding is because php is running 64 bit as opposed to 32 bit js.

Can anyone tell me the exact reason and if this could be solved so that both operations result in same value. Thanks!

4
  • 1
    stackoverflow.com/questions/24154381/… Commented Aug 30, 2016 at 18:02
  • There is no problem. This is the same result, just interpreted differently. Commented Aug 30, 2016 at 19:37
  • @harold, Ok, then how to make that same result look like as PHP's result? Commented Jul 27, 2017 at 3:23
  • @Green you can make it look unsigned with >>> 0, if you continue with other integer operation it'll just go back to signed again so it's mostly (but not entirely) a cosmetic change. Commented Jul 27, 2017 at 11:30

1 Answer 1

-1

2,147,483,647 is the biggest possible positive value for an integer in 32 bit computing, (it's 2^16, half of the 32 bits we have, the other half are reserved for negative numbers.)

Once you use a number bigger than that in a 32 bit system you start getting screwy results as the computer thinks it's a negative number. see https://en.wikipedia.org/wiki/Integer_(computer_science)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.