Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below IS ONE SU their function and how to correct it. int leftnost Oxf_pos(unsigned int n) { int le resulte-1 unsigned intake Oxf; /* 1
Below IS ONE SU their function and how to correct it. int leftnost Oxf_pos(unsigned int n) { int le resulte-1 unsigned intake Oxf; /* 1 1 297 / 3 / while (nask - Oxf00000000 88 i (28) if ((n & sk) - ) result i /* 5 * /* 6*/ y 7 / mask You can only make one modification to the function, so for example you can not write a completely new function. The function can be corrected by making only one addition, deletion, or change. State specifically what change you want to make and the line number in the function where it should be made: If you want to delete a line, just say so and give its number. If you want to insert a new line, just say where it should be inserted (which line number) and exactly what it should say). If you want to change a line give its number and say exactly how it should be changed. (You can also add curly braces if you want; we don't even consider them to be a modification) We gave an exam to a class of students remarkably like you that had a question asking them to write a function with the following prototype int teftast_af_cos(unsigned int>> The function should find the leftmost occurrence of the bit pattern Oxf (just four consecutive 1 bits) in its parameter n and return the number of the bit position where that occurrence of Oxf began in n (meaning the rightmost bit where Oxf began). (We consider the rightmost bit of n to be the oth bit) (In other words, the function should return the largest value of i such that bitsi through i + 3 of n are all 1s.) If n does not contain any occurrence of Oxf the function should just return - 1. Note that Oxf can appear starting anywhere- the oth bit, the 1st bit the 2nd bit the 3rd bit, etc. The function can assume that an unsigned int has 32 bits, like on the Grace machines. Here are some examples, with the four consecutive 1 bits underlined that we are referring to (when they appeark if nis n's binary representation is the function should return Ox 0000 0000 0000 0000 0000 0000 0000 1111 0 Oxle oooo 0000 0000 0000 0000 0000 0001 1110 Oxfofo 0000 0000 0000 0000 1111 0000 1111 0000 12 Oxf0000000 1111 0000 0000 0000 0000 0000 0000 0000 28 Oxo 0000 0000 0000 0000 0000 0000 0000 0000 - 1 OxbOcOdde 0000 1011 0000 1100 0000 1101 0000 1110 -1 Below is one student's answer. Unfortunately, their function compiles and runs but has a bug. Figure out what is wrong with their function and how to correct it. int left ost_bf_pos(unsigned inta) int 1-0, results -1 unspresint rasti while (90000 1 38) 24 cm ) ) / 1 12 731 47 / 5 / /* 6 * 7. 787 Below IS ONE SU their function and how to correct it. int leftnost Oxf_pos(unsigned int n) { int le resulte-1 unsigned intake Oxf; /* 1 1 297 / 3 / while (nask - Oxf00000000 88 i (28) if ((n & sk) - ) result i /* 5 * /* 6*/ y 7 / mask You can only make one modification to the function, so for example you can not write a completely new function. The function can be corrected by making only one addition, deletion, or change. State specifically what change you want to make and the line number in the function where it should be made: If you want to delete a line, just say so and give its number. If you want to insert a new line, just say where it should be inserted (which line number) and exactly what it should say). If you want to change a line give its number and say exactly how it should be changed. (You can also add curly braces if you want; we don't even consider them to be a modification) We gave an exam to a class of students remarkably like you that had a question asking them to write a function with the following prototype int teftast_af_cos(unsigned int>> The function should find the leftmost occurrence of the bit pattern Oxf (just four consecutive 1 bits) in its parameter n and return the number of the bit position where that occurrence of Oxf began in n (meaning the rightmost bit where Oxf began). (We consider the rightmost bit of n to be the oth bit) (In other words, the function should return the largest value of i such that bitsi through i + 3 of n are all 1s.) If n does not contain any occurrence of Oxf the function should just return - 1. Note that Oxf can appear starting anywhere- the oth bit, the 1st bit the 2nd bit the 3rd bit, etc. The function can assume that an unsigned int has 32 bits, like on the Grace machines. Here are some examples, with the four consecutive 1 bits underlined that we are referring to (when they appeark if nis n's binary representation is the function should return Ox 0000 0000 0000 0000 0000 0000 0000 1111 0 Oxle oooo 0000 0000 0000 0000 0000 0001 1110 Oxfofo 0000 0000 0000 0000 1111 0000 1111 0000 12 Oxf0000000 1111 0000 0000 0000 0000 0000 0000 0000 28 Oxo 0000 0000 0000 0000 0000 0000 0000 0000 - 1 OxbOcOdde 0000 1011 0000 1100 0000 1101 0000 1110 -1 Below is one student's answer. Unfortunately, their function compiles and runs but has a bug. Figure out what is wrong with their function and how to correct it. int left ost_bf_pos(unsigned inta) int 1-0, results -1 unspresint rasti while (90000 1 38) 24 cm ) ) / 1 12 731 47 / 5 / /* 6 * 7. 787
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started