Question: C code Bit vectors are used to provide dense storage and allow fast manipulation of the entire group of bits at once. In a bit
C code
Bit vectors are used to provide dense storage and allow fast manipulation of the entire
group of bits at once. In a bit vector, each individual bit is designated to represent a particular
value and a bit is turned on to indicate its corresponding value is contained in the set. In
this problem, we have sets drawn from the range [1-9]. A set is represented using an unsigned
short (16 bits). The bit at the nth position (counting from least significant bit at the 0th
position) is designated to represent the value n. The bits in the positions 1 to 9 represent the
set membership and the other seven bits of the short are ignored. Below is a few example
sets and their corresponding bit vectors.
0000000000000000 // {}
0000001010100100 // {2 5 7 9}
0000000000001110 // {1 2 3}
Write the makeSet function to create a bit vector set from an array. The arguments to the
function are an array of integer values and the array count. The function 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. You may assume
that no value in the array will be outside the range 1-9.
unsigned short makeSet(int values[], int nvalues)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
