Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C, Thanks. void set-flag (unsigned int flag-holder [], int flag-position); void unset-flag (unsigned int flag-holder [1, int flag-position); int check_flag (unsigned int flag-holder [],

image text in transcribedimage text in transcribedIn C, Thanks.

void set-flag (unsigned int flag-holder [], int flag-position); void unset-flag (unsigned int flag-holder [1, int flag-position); int check_flag (unsigned int flag-holder [], int flag-position); void display -32_flags-as-array (unsigned int flag-holder); void display-flags (unsigned int flag-holder [], int size); int main(int argc, char* argv (1) unsigned int flag-holder [5] = { 0 };// Set the first integer to zero //and all others to zero by default. set-flag (flag-holder , 3); set-flag (flag-holder, 16): set_flag (flag-holder, 31); set-flag (flag-holder, 87); display_flags (flag-holder, 5); printf(" "); unset_flag (flag-holder, 31); unset-flag (flag-holder, 3); set-flag (flag-holder, 99); set_flag (flag-holder, 100); display-flags (flag-holder, 5); return 0; Here I have changed the functions so that they take an array of integers instead of just one integer. This allows me to imagine that I have a long array of bits instead of an array of integers. The functions can now set, unset, check and display flags for any bit in the array of 5 integers that I have made and should work for any size array as long as your bit index is in bounds of your array). I also changed the display behavior. Daily 4 displayed the flags as you would see them in a binary number but since this program is moving away from the idea of a binary number to store bits and moving toward the idea of having an array of bits the display_32 flags as array function will display the [O bit first then [1] and so on up to 31 whereas the display_32_flags function in daily 4 displays the 31] bit first and down to O. Similarly the display flags function now takes an array of integers and displays one integer per line using the display-32 flags_as_array function. Your output should look exactly like the following: 0001 0000 0000 0000 1000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0001 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 You may want to be careful about how you call your check_flag function from inside the display_32_flags_as_array function since that function receives an integer and check_flag is expecting an array. How can you overcome this obstacle? void set-flag (unsigned int flag-holder [], int flag-position); void unset-flag (unsigned int flag-holder [1, int flag-position); int check_flag (unsigned int flag-holder [], int flag-position); void display -32_flags-as-array (unsigned int flag-holder); void display-flags (unsigned int flag-holder [], int size); int main(int argc, char* argv (1) unsigned int flag-holder [5] = { 0 };// Set the first integer to zero //and all others to zero by default. set-flag (flag-holder , 3); set-flag (flag-holder, 16): set_flag (flag-holder, 31); set-flag (flag-holder, 87); display_flags (flag-holder, 5); printf(" "); unset_flag (flag-holder, 31); unset-flag (flag-holder, 3); set-flag (flag-holder, 99); set_flag (flag-holder, 100); display-flags (flag-holder, 5); return 0; Here I have changed the functions so that they take an array of integers instead of just one integer. This allows me to imagine that I have a long array of bits instead of an array of integers. The functions can now set, unset, check and display flags for any bit in the array of 5 integers that I have made and should work for any size array as long as your bit index is in bounds of your array). I also changed the display behavior. Daily 4 displayed the flags as you would see them in a binary number but since this program is moving away from the idea of a binary number to store bits and moving toward the idea of having an array of bits the display_32 flags as array function will display the [O bit first then [1] and so on up to 31 whereas the display_32_flags function in daily 4 displays the 31] bit first and down to O. Similarly the display flags function now takes an array of integers and displays one integer per line using the display-32 flags_as_array function. Your output should look exactly like the following: 0001 0000 0000 0000 1000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0001 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 You may want to be careful about how you call your check_flag function from inside the display_32_flags_as_array function since that function receives an integer and check_flag is expecting an array. How can you overcome this obstacle

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions