Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago