新人Y子のプログラミングのお部屋28

論理和プログラム続きです。

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]さて、前回のプログラムを見てみましょう。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-normal.png" name="新人Y子"]このプログラムは、「11」 と 「22」 を論理和(OR)をするプログラムでしたね。
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]はい。それでは、このプログラムを実行してみましょう。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-normal.png" name="新人Y子"]プログラムをCoding Groundに入力して、実行しました。
「計算結果は、31 です」と出ました。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-hatena.png" name="新人Y子"]なぜ、11 と 22 の論理和(OR)は、31なのですか?
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]はい。演算の手順を説明しますね。
まず、次の表を見てください。10進数と2進数の対応表です。
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]まず、入力の11と22を2進数にしてください。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-normal.png" name="新人Y子"]11は、「1011」ですね。
22は、「10110」ですね。
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]この「1011」と「10110」を各桁ごと論理和(OR)してください。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-normal.png" name="新人Y子"]桁を合わせてこんな感じですか?

論理和の結果は、「11111」で合っていますか?
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]はい、その通りです。
では、この「11111」を10進数に戻してください。
[/speech_bubble]

[speech_bubble type="std" subtype="R1" icon="sanoyu-bikkuri.png" name="新人Y子"]31ですね。なるほどー
[/speech_bubble]

[speech_bubble type="std" subtype="L1" icon="itokuma-normal.png" name="しげちゃん先生"]では、宿題です。
ほぼ、今とほぼ同じプログラムですが、計算を論理積(AND)に変更しました。
このプログラムの実行結果を求めてください。
[/speech_bubble]


[speech_bubble type="std" subtype="R1" icon="techtrageman-normal.png" name="テクトレージマン"]次回に続く[/speech_bubble]

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

目次