用C逻辑运算符 [英] Logical Operators in C
问题描述
我有麻烦试图了解逻辑运算符在C.工作我已经明白是怎么位级运营商的工作,我也知道,逻辑运算符把非零参数如重新presenting TRUE和零参数作为重presenting FALSE
I am having trouble trying to understand how logical operators work in C. I already understand how the bit-level operators work, and I also know that logical operators treat nonzero arguments as representing TRUE and zero arguments as representing FALSE
不过,说我们有0x65和放大器;&安培;将0x55。我不明白为什么这怎么操作提供了为0x01。
But say we have 0x65 && 0x55. I do not understand why and how this operations gives 0x01.
我试着将它转换为二进制,但我无法弄清楚它是如何工作
I tried to convert it to binary, but I cannot figure out how it works
推荐答案
的&放大器;&安培;
是一个逻辑和
(而不是&安培;
,这是一个的按位的和
)。它关心只有它的操作数作为零/非零值。零被认为是假
,而非零被视为真正
。
The &&
is a logical AND
(as opposed to &
, which is a bitwise AND
). It cares only that its operands as zero/non-zero values. Zeros are considered false
, while non-zeros are treated as true
.
在您的情况下,两个操作数不为零,因此,他们都以真正
,导致的结果是真正$处理C $ C>为好。 c重新presents
真正
为 1
,解释你的操作的整体效果。
In your case, both operands are non-zero, hence they are treated as true
, resulting in a result that is true
as well. C represents true
as 1
, explaining the overall result of your operation.
如果您更改操作&安培;
,你会得到一个按位运算。 0x65和放大器;将0x55
会给你×45
的结果。
If you change the operation to &
, you would get a bitwise operation. 0x65 & 0x55
will give you a result of 0x45
.
这篇关于用C逻辑运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!