Question: Language: C 4. (40 points) Implement a function unsigned char *prime_vector (unsigned long num) that accepts a number num and returns a bit vector that

Language: C

Language: C 4. (40 points) Implement a function unsigned char *prime_vector (unsignedlong num) that accepts a number num and returns a bit vector

4. (40 points) Implement a function unsigned char *prime_vector (unsigned long num) that accepts a number num and returns a bit vector that indicates all the prime numbers less than number num. You must allocate the appropriate amount of memory. For example, if num is 12, then the return character array must have 2 bytes with the following bit configuration: 7 6 1 0 5 4 3 2 1 0 1 0 1 1 0 0 OxAC 15 0 14 0 13 0 12 0 0x8 11 1 10 0 9 8 0 0 Notice that all the bits in the last byte that correspond to num or above is set to 0 even though there may be a prime within (e.g., 13). Here is another example if num is 30. 14 0 9 |0 8 0 7 6 5 4 3 2 1 0 15 1|0 1|0 |1|1|0|0||0 OxAC 23 22 21 20 19 18 17 16 31 1 0 0 0 1 0 1 0 0 0x8A 13 12 11 10 1|0 |10 0x28 29 28 27 26 1 0 1 0 0 0x20 30 0 25 0 24 0 You are encouraged to implement helper functions (e.g., is-prime, set bit). Sample inputs and outputs: num Expected return bytes OxAC 0x28 0x8A 0x20 Ox0 Ox0 Ox0 Ox4 OxC OxAC 0x8 OxAC Ox0 OxAC 0x28 0x8A OxAO Ox20 0x8A 0x20 0x28 0xAC 0x28 0x8A 0xAO 0x20 0x8A 0x200x28 0x88 0x82 0x8 0x2 0xA2 0x28 0x2 0x0 | 124

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!