任意の8ビットのデータXと, 8ビットのデータ00001111をビットごとに排他的論理和をとった結果はどれか。ここで, 各1ビットのデータAとデータBの排他的論理和をとった結果Cの値は次のように表される。また, データの左方を上位, 右方を下位と呼ぶ。 排他的論理和
| A | B | C |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
This question's explanation and your answers so far.
任意の8ビットのデータXと, 8ビットのデータ00001111をビットごとに排他的論理和をとった結果はどれか。ここで, 各1ビットのデータAとデータBの排他的論理和をとった結果Cの値は次のように表される。また, データの左方を上位, 右方を下位と呼ぶ。 排他的論理和
| A | B | C |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
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.
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.
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.