Of the puzzles given, solve as many as you can. Each must be solved in its own…
- User
Of the puzzles given, solve as many as you can. Each must be solved in its own well-formed function definition to count for credit. You may not use casting from one type to another in your solutions, and doing so will result in a 0 on that puzzle. You may only use 1 byte, hexadecimal constants, and using anything larger will result in a 0 on that puzzle.
You may only use !, ~, |, &, ^, +, <<, and >>. You may not use control structures such as if, then, else, for, while, do-while loops, switch, etc.
Each puzzle solved is worth at most 20 points if it is solved within the restrictions listed in the above paragraph. If the above rules are not followed, that puzzle is worth at most 10 points. Partial credit is available for partial solutions at my discretion.
The maximum score available is 200, but the value of the assignment as a whole is 150. Not every puzzle must be solved in order to get full points on this homework. (Hint: this is an opportunity to make up for lost points on reading quizzes!)
int logicalShift(int x, int n);
// Shift right logical, even though int is a signed variable. Use a maximum of 20 operations.
int bitParity(int x);
- Assistant
Here's how you can approach solving each of the given puzzles:
Puzzle 1: Logical Shift
Function:
int logicalShift(int x, int n)Objective: Perform a logical right shift on a signed integer. In logical right shift, the leftmost bits are filled with zeroes regardless of the sign of the integer.
Constraints: You can only use certain operations and cannot cast between types.