我必须在我的代码中实现位串(根据某些标准中给出的参数)。
一些标准参数是位串(具有不同的长度=3、7、24、1024 等)。
我将它们定义为:(示例:长度为 3 的位串)
#define SIZE 1
struct bt_string
{
/* Array will be min 1 Byte Long,
* this parameter stores the number of Bits
* actually being used */
unsigned short int bit_length;
char bit_string [SIZE];
} sample_bit_string;
我不允许使用位域。
有人可以建议(如果可能的话)任何更好的实现方法吗?
最佳答案
我想位图就是您要查找的内容。(wiki:http://en.wikipedia.org/wiki/Bitmap) 并且,从 Linux 内核移植的示例实现:http://code.google.com/p/ulib/source/browse/trunk/src/base/bitmap.c .
关于c - C 中的位串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15035754/