# Thread: Design a struct to represent a set?

1. ## Design a struct to represent a set?

Im trying to design a struct to represent a set. The struct will hold the maximum set size and a pointer to an array holding 1 bit per possible element of the set.

But How do I create a pointer to an array holding 1 bit per possible element of the set. Seems impossible?How can this be one in c? 2. Well you would use an array of unsigned integers.

The number of bits you have in each unsigned int is
n = CHAR_BIT*sizeof(unsigned int);

So you
- use /n to get the array element.
- use %n to get the bit position within an element.
- use << >> & | to manipulate that bit. 3. Im still confused. Can you show an example of say, getting array element 3?
I dont understand these two
- use /n to get the array element.
- use %n to get the bit position within an element. 4. What do you want to know about division and modulus. 5. Im familiar with div and mod but using them to get say position 3 i dont understand. 6. Well if you have 32 bits in each integer, and an array of integers, then

The array index is given by 3 / 32
The bit position within that integer is given by 3 % 32

The rest is just bit twiddling. Popular pages Recent additions array, bit, design, set, struct 