Jump to content

Recommended Posts

In doing user permissions, I'm having a weird bug with a bitwise and. The values are being stored correctly, yet when the 'and' is done the value that returns varies by which server the command is done on. Example:

 

$user["permissions"] = 54975580511 //0x7FFFFFDF47

$CLIENT_VIEW = 4294967296 // 0x10000000

 

$user["permissions"] & $CLIENT_VIEW => 0 on one of our servers.

 

Any suggestions?

 

Link to comment
https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/
Share on other sites

I would expect the answer to be same as $CLIENT_VIEW although my server gives 0

 

<?php
echo base_convert('7FFFFFDF47', 16,2);
echo '<br>';
echo '000000' . base_convert('4294967296', 10,2);


?>

-->

111111111111111111111111101111101000111
000000100000000000000000000000000000000 

Link to comment
https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-381620
Share on other sites

I would expect the answer to be same as $CLIENT_VIEW although my server gives 0

 

<?php
echo base_convert('7FFFFFDF47', 16,2);
echo '<br>';
echo '000000' . base_convert('4294967296', 10,2);


?>

-->

111111111111111111111111101111101000111
000000100000000000000000000000000000000 

That is exactly what I would expect as well, yet one of our servers gives 0, just like yours. Any idea what might yield this result? Why would the server give 0, and not the value of $CLIENT_VIEW?

 

In binary, I would expect 000000100000000000000000000000000000000, which should be non-zero.

Link to comment
https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382204
Share on other sites

Actually that's very close to a working solution. You just need to make $a and $b string values

 

<?php

$a = '549755805511';
$b = '004294967296';

$a = base_convert($a, 10, 2);
$b = base_convert($b, 10, 2);

$c = base_convert(($a & $b), 2, 10);

var_dump($c);     // string(10) "4294967296" 

?>

Link to comment
https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382242
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.