0

I can't find the solution for very easy question.

Code in JavaScript:

var x = -1 ^ 0xF00F9344;

In this case x value is 267414715

Code in PHP:

$x = -1 ^ 0xF00F9344;

The result is -4027552581

Any idea, how to get 267414715 (correct) result in PHP?

3
  • Works for me. Commented Sep 19, 2011 at 9:53
  • Yes, works here too. What version of PHP do you have? and on what hardware? Commented Sep 19, 2011 at 9:54
  • Works for me on a 32bit machine, but I get the same beaviour on a 64bit machine. Commented Sep 19, 2011 at 10:08

1 Answer 1

4

While javascript bit operations are always 32-bit, php depends on the platform's word size:

on a 32-bit platform

$n    = "11110000000011111001001101000100"
-1^$n = "00001111111100000110110010111011"  = 267414715

on a 64 bit platform

$n    = "0000000000000000000000000000000011110000000011111001001101000100"
-1^$n = "1111111111111111111111111111111100001111111100000110110010111011" = -4027552581
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.