Question

I have to implement Bit-Strings in my Code (as per the parameters given in some Standard).

Some of the standard parameters are Bit-Strings (with different Lengths=3, 7, 24, 1024 etc).

I have defined them as: (Example: Bit-String of Length 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;

I am not allowed to use bit-fields.

Can someone please suggest (if possible) any better way to implement this?

Was it helpful?

Solution

I suppose that the bitmap is what you are looking for.(wiki:http://en.wikipedia.org/wiki/Bitmap) And, a sample implementation ported from Linux kernel:http://code.google.com/p/ulib/source/browse/trunk/src/base/bitmap.c.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top