Question: For each function below, trace through it with reasonably small integer values ( give the trace results as numbers in base 1 0 ) .

For each function below, trace through it with reasonably small integer values (give the trace results as numbers in base 10). What does each function do (give a high-level summary)?
Requirement: You should assume integers are only 8 bits for the purpose of this exercise. The sign bit is the leftmost of the 8 bits.
int mystery1(int a, int b){
int c = a - b,
d =(c >>7) & 1,
mystery = a - c * d;
return mystery;
}
Trace: mystery1(3,7) returns ______
Trace: mystery1(8,7) returns ______
Summary: ____________________________________________________________________________
int mystery2(int x){
return (x && !(x & (x -1)));
}
Trace: mystery2(1) returns ______
Trace: mystery2(2) returns ______
Trace: mystery2(3) returns ______
Trace: mystery2(4) returns ______
Trace: mystery2(5) returns ______
Trace: mystery2(6) returns ______
Trace: mystery2(7) returns ______
Trace: mystery2(8) returns ______
Summary: ____________________________________________________________________________
int mystery3(int x, int y){
int s, c;
s = x ^ y;
c = x & y;
while (c !=0){
c = c <<1;
x = s;
y = c;
s = x ^ y;
c = x & y;
}
return s;
}
Trace: mystery3(5,7) returns ______
Trace: mystery3(2,8) returns ______
Summary: _______________

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 Programming Questions!