#12
by みけCAT » 7年前
KRNKRS さんが書きました:1.unsigned char button[16] の中身が {'0', '1', '1', '0', ....} と16個の文字が連なっているのを、
'0', '1', ... という文字 (ASCIIの場合48, 49, ... という数値) ではなく、0, 1, ...という数値でしょう。
KRNKRS さんが書きました:2.long long p* にキャストすることで { {'0', '1', '1', '0', ....(8個)}, {'1', '0', '1', '1', ....(8個)} }に分割し、
1.と同様にデータが違います。
KRNKRS さんが書きました:3.「||」で二つをOR演算することで、「1」を取り出している。
「『1』を取り出している」の意味がよくわからないですが、||演算子の結果を整数にしたものは両辺がともにfalseなるならfalse、そうでなければtrueになります。
整数は0はfalse、0以外はtrueになります。
N3337 4.12 Boolean conversionsより引用
1
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a
prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false;
any other value is converted to true.
N3337 5.15 Logical OR operatorより引用
1
The || operator groups left-to-right. The operands are both contextually converted to bool (Clause 4). It
returns true if either of its operands is true, and false otherwise. Unlike |, || guarantees left-to-right
evaluation; moreover, the second operand is not evaluated if the first operand evaluates to true.
KRNKRS さんが書きました:よく考えたらlong long型なので違いました。
long long型は関係なく違います。
KRNKRS さんが書きました:いづれかの箇所に1が入っている」 = 「0以外の値となる」 = 「trueとみなす」
となると思われるので、それを二つ行っているわけですね!
そのようですね。
[quote="KRNKRS" id=3,19160,145213]1.unsigned char button[16] の中身が {'0', '1', '1', '0', ....} と16個の文字が連なっているのを、[/quote]
'0', '1', ... という文字 (ASCIIの場合48, 49, ... という数値) ではなく、0, 1, ...という数値でしょう。
[quote="KRNKRS" id=3,19160,145213]2.long long p* にキャストすることで { {'0', '1', '1', '0', ....(8個)}, {'1', '0', '1', '1', ....(8個)} }に分割し、[/quote]
1.と同様にデータが違います。
[quote="KRNKRS" id=3,19160,145213]3.「||」で二つをOR演算することで、「1」を取り出している。[/quote]
「『1』を取り出している」の意味がよくわからないですが、||演算子の結果を整数にしたものは両辺がともにfalseなるならfalse、そうでなければtrueになります。
整数は0はfalse、0以外はtrueになります。
[url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf]N3337[/url] 4.12 Boolean conversionsより引用
[quote]
1
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a
prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false;
any other value is converted to true.
[/quote]
N3337 5.15 Logical OR operatorより引用
[quote]
1
The || operator groups left-to-right. The operands are both contextually converted to bool (Clause 4). It
returns true if either of its operands is true, and false otherwise. Unlike |, || guarantees left-to-right
evaluation; moreover, the second operand is not evaluated if the first operand evaluates to true.
[/quote]
[quote="KRNKRS" id=3,19160,145217]よく考えたらlong long型なので違いました。[/quote]
long long型は関係なく違います。
[quote="KRNKRS" id=3,19160,145217]いづれかの箇所に1が入っている」 = 「0以外の値となる」 = 「trueとみなす」
となると思われるので、それを二つ行っているわけですね![/quote]
そのようですね。