Jump to content

Weird Bitwise Bug


gmoeck

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.