1

我必须在我的代码中实现位串(根据某些标准中给出的参数)。

一些标准参数是位串(具有不同的长度=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;

我不允许使用位域。

有人可以建议(如果可能的话)任何更好的方法来实现这一点吗?

4

1 回答 1

3

我想位图是您正在寻找的。(wiki:http ://en.wikipedia.org/wiki/Bitmap )并且,从 Linux 内核移植的示例实现:http ://code.google.com/p /ulib/source/browse/trunk/src/base/bitmap.c

于 2013-02-23T01:16:46.917 回答