帮助按位操作 [英] Help With Bitwise Operations
问题描述
我正在尝试围绕现有代码进行一些工作,这些代码使用按位
操作来管理传递给函数的标志,而且我非常
坦率地未装备这样做。我从来没有做过多少按位操作,我今天所做的所有阅读似乎都没有帮助我。我希望这里有人可以提供补救措施
课程。给出以下常数:
define(''FLAG_1,1);
define(''FLAG_2'',2);
define(''FLAG_3'',4);
define(''FLAG_4'',8);
define(''FLAG_5'',16 );
define(''FLAG_6'',32);
define(''FLAG_7'',64);
define( ''FLAG_8'',128);
define(''FLAG_9'',256);
define(''FLAG_10'',512);
define(''FLAG_11'',1024);
define(''FLAG_12'',2048);
我''打这个电话:
$ foo = my_function(''arg1'',''arg2'',FLAG_1 | FLAG_6 | FLAG_4);
给这个函数签名:
函数my_function($ arg1,$ arg2 ='''blah'',$ flags = NULL)
在函数内部,如果我只是回显$ args的值,我会得到41。
这是正确的吗?从我的阅读来看,它看起来并不正确,但它可能只是我在这方面的无知。任何帮助阅读和
了解这些东西将非常感激。
谢谢。
Rob
foo = my_function(''arg1'',''arg2'',FLAG_1 | FLAG_6 | FLAG_4);
给这个函数签名:
函数my_function(
arg1,
arg2 =' '嗒嗒',
I''m attempting to do some work around existing code that uses bitwise
operations to manage flags passed into a function and I''m quite
frankly unequipped to do so. I''ve never done much with bitwise
operations and all the reading I''ve done today doesn''t appear to be
helping me much. I''m hoping someone here can provide a remedial
lesson. Given the following constants:
define(''FLAG_1, 1);
define(''FLAG_2'', 2);
define(''FLAG_3'', 4);
define(''FLAG_4'', 8);
define(''FLAG_5'', 16);
define(''FLAG_6'', 32);
define(''FLAG_7'', 64);
define(''FLAG_8'', 128);
define(''FLAG_9'', 256);
define(''FLAG_10'', 512);
define(''FLAG_11'', 1024);
define(''FLAG_12'', 2048);
I''m making this call:
$foo = my_function ( ''arg1'', ''arg2'', FLAG_1|FLAG_6|FLAG_4 );
To this function signature:
function my_function ( $arg1, $arg2=''blah'', $flags=NULL )
Inside the function, if I just echo the value of $args I get "41".
Is that correct? From my reading, it doesn''t seem correct, but it may
just be my ignorance in this area. Any assistance reading and
understanding this stuff would be much appreciated.
Thanks.
Rob
foo = my_function ( ''arg1'', ''arg2'', FLAG_1|FLAG_6|FLAG_4 );
To this function signature:
function my_function (
arg1,
arg2=''blah'',
这篇关于帮助按位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!