检查一个位掩码值是否包含在多个位掩码值的总和中

Check if a bitmask value is contained in the sum of many bitmask values

我有以下位掩码值规范:

// Structure of Database:
// SC_NAME, flag
//
// flag    1  - SC cannot be removed by death.
//         2  - SC cannot be saved.
//         4  - SC cannot be reset by dispell.
//         8  - SC cannot be reset by clearance.
//         16 - SC considered as buff and be removed by Hermode and etc.
//         32 - SC considered as debuff and be removed by Gospel and etc.
//         64 - SC cannot be reset when MADO Gear is taken off.
//        128 - SC cannot be reset by 'sc_end SC_ALL' and status change clear.
//        256 - SC can be visible for all players

下面是位掩码的用法示例:

SC_ENDURE, 21

以上表示:

SC_ENDURE: cannot be removed by death and dispel and considered as buff. (16 + 4 + 1 = 21)

我有一个 CSV 列表(例如经过裁剪)要检查,它看起来像这样:

SC_PROVOKE, 32
SC_ENDURE, 21
SC_HIDING, 4
SC_CLOAKING, 6
SC_TWOHANDQUICKEN, 24
SC_CONCENTRATION, 16
SC_ENCHANTPOISON, 16
SC_ORCISH, 2

我想要做的是遍历列表 select 所有被认为是 buff 16 的效果到一个列表中,其他到另一个列表中。

使用上面的例子;你如何检查 16 是否存在于位掩码 21 的总和中?

这是我迄今为止尝试过的方法(由于我对位掩码缺乏了解)并且没有任何运气:

<pre>
<?php

$buff_list = [];
$not_buffs = [];

if (($handle = fopen("data.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        list ($effect_code, $bitmask_value) = $data;
        $effect_code = trim($effect_code);
        $bitmask_value = (int)trim($bitmask_value);
        if (16 | $bitmask_value) {
            $buff_list[] = $effect_code;
        } else {
            $not_buffs[] = $effect_code;
        }
    }
    fclose($handle);
}

print_r($buff_list);
echo "<hr>";
print_r($not_buffs);

我尝试的代码是将所有效果都放入 $buff_list,我不确定我这样做是否正确。

替换

(16 | $bitmask_value)

(16 & $bitmask_value)

编辑帮助澄清:

(16 | $bitmask_value) = &bitmask_value 以及 16.
中的所有标志 例子:(1 | 16) = 17, ((4 | 16) | 16) = (4 | 16) = 20

(16 & $bitmask_value) = &bitmask_value中的所有标志 also in 16.
例子:(1 & 16) = 0, ((4 | 16) & 16) = 16, ((1 | 2 | 4) & (2 | 4 | 8)) = (2 | 4) = 6