C中的位串

时间:2013-02-23 01:00:07

标签: c bitstring

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

一些标准参数是Bit-Strings(不同长度= 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;

我不允许使用位字段。

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

1 个答案:

答案 0 :(得分:3)

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

相关问题