gmoeck Posted October 30, 2007 Share Posted October 30, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/ Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 $user["permissions"] = 54975580511 //0x7FFFFFDF47 well first off 0x7FFFFFDF47= 549755805511 you say on one of your servers you get 0 but i don't see how your get any other result i assume you was expecting 34 ! Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-381613 Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-381620 Share on other sites More sharing options...
gmoeck Posted October 31, 2007 Author Share Posted October 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382204 Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 I guess the 31 bit (signed int) limit has something to do with it. The "1" is bit 33 if I counted correctly. Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382223 Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 i used <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382231 Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 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" ?> Quote Link to comment https://forums.phpfreaks.com/topic/75418-weird-bitwise-bug/#findComment-382242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.