Skip to content

平成30年度 秋期 ITパスポート試験 問79

This question's explanation and your answers so far.

問79
頻出度★★☆

8ビットの2進データXと00001111について,ビットごとの論理積をとった結果はどれか。ここでデータの左方を上位,右方を下位とする。

出典 平成30年度 秋期 ITパスポート試験 問79
解説

問 79

  • Incorrectア

    The side that is kept and the side that becomes 0 are reversed. A result of “the lower 4 bits become 0 and the upper 4 bits are kept” occurs when the mask is 11110000 (1 in the upper part, 0 in the lower part). With the mask 00001111, the positions of the 0s (the upper part) are cleared and the positions of the 1s (the lower part) are kept, so this description does not apply.

  • Incorrectイ

    The claim that “the lower 4 bits all become 1” is a property of logical OR, not AND. In AND, operating with 1 does not fix a bit to 1; it merely keeps the original value. Furthermore, the correspondence of which side (upper/lower) is kept is also reversed, making it doubly wrong.

  • ウ

    正解 The mask constant 00001111 has 0000 in its upper 4 bits and 1111 in its lower 4 bits. Logical AND gives 1 only when both bits are 1, and 0 otherwise; therefore ANDing any bit with 0 always yields 0 (the value is cleared), while ANDing with 1 keeps the original value unchanged. So when X is ANDed with 00001111, the upper 4 bits all become 0 (AND with 0), and the lower 4 bits keep X's original value (AND with 1). This matches choice ウ, “the upper 4 bits all become 0, and the lower 4 bits of X remain unchanged”.

  • Incorrectエ

    The point that “the upper 4 bits all become 1” is wrong. The upper 4 bits of the mask are 0, so the AND result is never 1 but always 0. Fixing a bit to 1 is a property of OR; AND cannot fill bits with 1.

ここがポイント
  • The basic property of AND in bit masking: “AND with 0 gives 0 (clears that bit)” and “AND with 1 keeps the original value (preserves that bit)”. Only the positions where the mask is 1 let the value pass through.
  • The difference in roles between AND and OR: AND (00001111) is a mask that extracts only the needed lower bits, whereas OR is the operation that sets specific bits to 1; do not confuse the two.
用語

Your answers