logo CodeStepByStep logo

make_set

Write a function named make_set that creates a bit vector set from a given array of values (arguments are an array of int and its size, as int [] and int). Returns an unsigned short that represents a bit vector set of the values from the array. The bits in positions 1-9 of the returned result mark the set membership, the remaining bits are zeros.

Precondition: every number in the values array is the range 1-9. Assume the array size is correct. Implementation can assume client is responsible for meeting precondition.

For example, if the input is {5, 3, 7}, then make_set returns 168 (binary 0000000010101000 -- note bit positions 5, 3, and 7 are 1).

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.