Question: The rules for completing lab include: All of these problems can be done with the eight operators: ! ~ & ^ | + < <
The rules for completing lab include:
All of these problems can be done with the eight operators:
! ~ & ^ | + << >>
and some require you to stick with just a subset of these.
You are also limited to constants with length at most 8-bits
i.e. you are limited to constants with two hexadecimal digits.
You must use straight-line code no loops or conditionals.
Each puzzle also has a rating of 1 (easiest) to 4 (hardest).
There is a limit on the number of operations you may use (just to eliminate brute force solutions).
Each puzzle is worth 5 points
Assignment:
Puzzle Six byteSwap - swaps the nth byte and the mth byte
Examples: byteSwap(0x12345678, 1, 3) = 0x56341278
byteSwap(0xDEADBEEF, 0, 2) = 0xDEEFBEAD
You may assume that 0 <= n <= 3, 0 <= m <= 3
Legal ops: ! ~ & ^ | + << >>
Max ops: 40
Rating: 2
int byteSwap(int x, int n, int m) { }
Puzzle Seven isPositive - Return 1 if x>0, return 0 otherwise
Difficulty Rating - 3
Legal Operators: ! ~ & ^ | + << >>
Max Ops: 12
isPositive(int x) { }
Puzzle Eight isLess - if x < y then return 1, else return 0
Example: isLess(4,5) = 1.
Legal ops: ! ~ & ^ | + << >>
Max ops: 30
Rating: 3
isLess(int x, int y) { }
Puzzle Nine threeFourths - multiplies by 3/4 rounding toward 0,
Should exactly duplicate effect of C expression (x*3/4), including overflow behavior.
Examples: ezThreeFourths(11) = 8
ezThreeFourths(-9) = -6
ezThreeFourths(1073741824) = -268435456 (overflow)
Legal ops: ! ~ & ^ | + << >>
Max ops: 12
Rating: 3
int threeFourths(int x) { }
Puzzle Ten bang - Compute !x without using !
Examples: bang(3) = 0, bang(0) = 1
Legal ops: ~ & ^ | + << >>
Max ops: 20
Rating: 4
int bang(int x) { }
Puzzle Eleven (Extra Credit) bitCount - returns count of number of 1's in word
Examples: bitCount(5) = 2, bitCount(7) = 3
Legal ops: ! ~ & ^ | + << >>
Max ops: 40
Rating: 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
