ITPEC FE Morning October 2022 Question 1

For an 8-bit binary integer, which of the following sets the least significant bit to 1 while leaving the other bits unchanged?

Explanation

OR with 00000001 — OR forces a bit to 1 where the mask has 1 and leaves it unchanged where the mask has 0.

For any bit x: x OR 0 = x, and x OR 1 = 1. The mask 00000001 has 0 in the seven upper positions and 1 in the least significant bit, so the upper bits pass through unchanged and the last bit becomes 1 whatever it was.

Answer (c)

Why not others:

  • •(a) AND with 00000001 — x AND 0 = 0, so it clears the seven upper bits and only keeps the LSB as it was
  • •(b) NAND with 11111110 — NAND is NOT of AND: the LSB does become 1, but each upper bit comes out as NOT x, so the other seven bits are inverted
  • •(d) XOR with 00000001 — XOR with 1 toggles the LSB: a 0 becomes 1, but a 1 becomes 0

Key rule: OR with a mask sets bits, AND with a mask clears bits, XOR with a mask toggles bits; a mask bit of 0 leaves the bit alone for OR and XOR, a mask bit of 1 does so for AND.

Basic Theory · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.