小编Gia*_*omo的帖子

验证二进制数组是否是C中另一个数组的子集

我需要验证字节数组(即,字符)中的位是否是相同类型的另一个数组的子集:例如,0001.0011(19)是0011.0011(51)的子集,而0000.1011(11)不是。

我开始玩按位运算,几乎用XOR / OR / XOR序列解决了它:

int is_subset (char *set_a, char *set_b, int size)
{
  /* The operation is performed with three bitwise operations, resulting in a
   * sequence of bits that will be equal to zero if set_a is a subset of
   * set_b. As a bonus, the positions where the sets differ will be
   * available in the resulting sequence, and thus the number of differing
   * positions can be obtained by counting the number of bits set …
Run Code Online (Sandbox Code Playgroud)

c bit-manipulation subset

3
推荐指数
3
解决办法
2252
查看次数

标签 统计

bit-manipulation ×1

c ×1

subset ×1