0

I do not understand, code

var_dump(decbin(0xFFFFFFFF), 0xFFFFFFFF);

print

string(32) "11111111111111111111111111111111" float(4294967295)

but if I get value using bitwise operations

$shift = 32;
$mask = ~((1 << (32 - $shift)) - 1);
var_dump(decbin($mask), $mask)

given

string(32) "11111111111111111111111111111111" int(-1)

How I can get 4294967295 ?

1 Answer 1

1

PHP does not support unsigned integers, and its likely that you have a signed 32bit integer, which is -1 for all bits set.

See http://www.php.net/manual/en/language.types.integer.php

However, you may be able to print it out anyway using printf('%u')

https://www.php.net/manual/en/function.sprintf.php

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.