110_quiz9.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --- exercises/110_quiz9.zig 2025-02-08 13:19:48.522641785 -0800
  2. +++ answers/110_quiz9.zig 2025-02-10 17:42:04.525004335 -0800
  3. @@ -108,7 +108,7 @@
  4. PORTB = 0b1100;
  5. print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB});
  6. print("^ {b:0>4} // (bitmask)\n", .{0b0101});
  7. - PORTB ^= (1 << 1) | (1 << 0); // What's wrong here?
  8. + PORTB ^= (1 << 2) | (1 << 0);
  9. checkAnswer(0b1001, PORTB);
  10. newline();
  11. @@ -116,7 +116,7 @@
  12. PORTB = 0b1100;
  13. print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB});
  14. print("^ {b:0>4} // (bitmask)\n", .{0b0011});
  15. - PORTB ^= (1 << 1) & (1 << 0); // What's wrong here?
  16. + PORTB ^= (1 << 1) | (1 << 0);
  17. checkAnswer(0b1111, PORTB);
  18. newline();
  19. @@ -170,7 +170,7 @@
  20. PORTB = 0b1001; // reset PORTB
  21. print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB});
  22. print("| {b:0>4} // (bitmask)\n", .{0b0100});
  23. - PORTB = PORTB ??? (1 << 2); // What's missing here?
  24. + PORTB = PORTB | (1 << 2);
  25. checkAnswer(0b1101, PORTB);
  26. newline();
  27. @@ -178,7 +178,7 @@
  28. PORTB = 0b1001; // reset PORTB
  29. print(" {b:0>4} // (reset state)\n", .{PORTB});
  30. print("| {b:0>4} // (bitmask)\n", .{0b0100});
  31. - PORTB ??? (1 << 2); // What's missing here?
  32. + PORTB |= (1 << 2);
  33. checkAnswer(0b1101, PORTB);
  34. newline();
  35. @@ -269,7 +269,7 @@
  36. PORTB = 0b1110; // reset PORTB
  37. print(" {b:0>4} // (initial state of PORTB)\n", .{PORTB});
  38. print("& {b:0>4} // (bitmask)\n", .{0b1011});
  39. - PORTB = PORTB & ???@as(u4, 1 << 2); // What character is missing here?
  40. + PORTB = PORTB & ~@as(u4, 1 << 2);
  41. checkAnswer(0b1010, PORTB);
  42. newline();
  43. @@ -277,7 +277,7 @@
  44. PORTB = 0b0111; // reset PORTB
  45. print(" {b:0>4} // (reset state)\n", .{PORTB});
  46. print("& {b:0>4} // (bitmask)\n", .{0b1110});
  47. - PORTB &= ~(1 << 0); // What's missing here?
  48. + PORTB &= ~@as(u4, 1 << 0);
  49. checkAnswer(0b0110, PORTB);
  50. newline();