Changelog:

Your Task

  1. Work on the corresponding lab first to get familiar with bit puzzles generally. [added 13 September:] Solutions to the lab are available on Collab under resources (posted after the lab was due) for you to reference.

  2. Go to the custom code environment. This is like the code environment for the lab, but with different problems.

  3. Solve all of the puzzles below using restricted subset of C (described below).

The C Subset

  1. You are restricted to a subset of C

    • Constants cannot exceed a single byte (between 0 and 255, or 0x00 and 0xff)
    • You cannot have any control constructs (no if, for, etc)
    • You can only use int-type values. You can use temporary variables and multiple statements, and we encourage you to do this.
    • All temporary variables must be initialized on declaration (e.g. int temporary = 0;)
    • All >> operators are arithmetic shifts (regardless of the types involved)
    • Each puzzle has a limited set of operators you are allowed to use
    • Each puzzle has a limit on the number of operators you are allowed to use
  2. Violating any of the above rules except the number of operators will result in 0 points. Partial credit is awarded if you have the correct functionality following all of the rules except the operator count.

Hints

Testing outside the Coding environment

Specific advice for the puzzles

allEvenBits

byteSwap

multFiveEighths

addOK

bitParity

Evaluation

Correctness points.
Each puzzle you must solve has been given a difficulty rating between 1 and 4 and is worth that many points. This is awarded all-or-nothing per puzzle: you either obeyed the coding rules and got all inputs correct or you did not.
Performance points.
There are an additional 2 points per puzzle that are awarded if you use a small number of operators. Again, this is all-or-nothing: you either met the limit or you did not.
Opt-in Competition
You may elect to provide a publicly visible name and have the operation counts of your working code logged on a competition scoreboard.