Skip to content

平成22年度 秋期 ITパスポート試験 問68

This question's explanation and your answers so far.

問68
頻出度★★☆

任意の8ビットのデータXと, 8ビットのデータ00001111をビットごとに排他的論理和をとった結果はどれか。ここで, 各1ビットのデータAとデータBの排他的論理和をとった結果Cの値は次のように表される。また, データの左方を上位, 右方を下位と呼ぶ。 排他的論理和

ABC
000
011
101
110
出典 平成22年度 秋期 ITパスポート試験 問68
解説

問 68

  • Incorrectア

    The roles of the high-order and low-order sides are reversed, and the result stated for the low-order side is wrong as well. The high-order 4 bits of the mask are 0000, so the high-order bits are not inverted; they remain unchanged. Also, the low-order 4 bits all becoming 1 is the result of taking the logical OR with 1111, not XOR; with XOR each low-order bit becomes 0 or 1 depending on the original value of X.

  • Incorrectイ

    The treatment of the high-order and low-order sides is completely reversed. Since the high-order bits of the mask 00001111 are 0, it is the high-order side that remains unchanged, and the low-order side, where the 1s are lined up, is the side that gets inverted. This option corresponds to the description you would get if the mask were misread as 11110000.

  • Incorrectウ

    The point that the low-order 4 bits are inverted is correct, but the description of the high-order 4 bits is wrong. XOR with 0 preserves the original value, so the high-order bits remain unchanged; they do not all become 0. Forcing the high-order bits to 0 is what happens when they are masked with 0000 using logical AND, which is a different operation from XOR.

  • エ

    正解 The correct answer is エ. Reading the truth table in the figure bit by bit shows that XOR (exclusive OR) has two faces: when the other input is 0 (0 XOR 0=0, 1 XOR 0=1) the result keeps the original value, and when the other input is 1 (0 XOR 1=1, 1 XOR 1=0) the result becomes the original value inverted. In other words, XOR works as a switch that preserves a bit when the other input is 0 and inverts it when the other input is 1. Here the mask is 00001111, whose high-order 4 bits are 0000 and whose low-order 4 bits are 1111. Therefore the high-order 4 bits of X are XORed with 0 and remain unchanged, while the low-order 4 bits are XORed with 1, so all of their 0s and 1s are inverted. This is exactly what エ states. Checking with a concrete example: when X=10100101, 10100101 XOR 00001111 = 10101010, which confirms that the high-order 1010 stays unchanged while the low-order 0101 is inverted into 1010.

ここがポイント
  • Property of XOR (exclusive OR): the result is 1 when the two inputs differ and 0 when they are the same. Viewed bit by bit, XOR with 0 leaves the value unchanged and XOR with 1 inverts it, so XOR can be used as a bit mask that inverts only the positions where a 1 is set.
  • Choosing the right masking operation: AND with 0 clears the corresponding bits to 0, OR with 1 sets them to 1, and XOR with 1 inverts them. The key to answering the question is to read which digits of the mask hold 0s and 1s and map them onto the high-order and low-order sides.
用語

Your answers