#include d set flag(unsigned int* f void unset flag(unsigned int * flag_holder,
ID: 3664587 • Letter: #
Question
#include d set flag(unsigned int* f void unset flag(unsigned int * flag_holder, int flag_position); int check flag(unsigned int flag holder, int flag_position); void display_32_flags (unsigned int flag_holder); void set_flag(unsigned int* flag_holder, int flag_position); d nolee int main(int argc, char* argv[]) unsigned int flag holder e; set_flag(&flag;_holder, 3); set flag(&flag;_holder, 16); set_flag(&flag; holder, 31) display_32 flags(flag_holder) unset_flag(&flag;_holder, 31); unset flag(&flag; holder, 3) set_flag(&flag; holder, 9); display_32 flags (flag_holder) return e; Write the code for the definition of unset flag and display_32_flags so that the output of your program looks like the following:Explanation / Answer
The main aim here is to toggle the bit using the unset_flag function. The function will be:
unset_flag(&flag_holder,int pos)
{
//pos is used to get the bit position.
flag_holder ^= 1 << x; //this will toggle the mentioned bit in flag_holder
}
display_32_flags(int flag_holder)
{
int c,k;
for (c = 31; c >= 0; c--)
{
k = flag_holder >> c;
if (k & 1)
printf("1");
else
printf("0");
if((c%4) == 0)
printf(" ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.