This is decimal 232. Taking | would have set the bit at all positions where at least one bit is set, i.e. would have produced binary 11 1111 1111, which is decimal 1023. Taking ^ would have set the bit at all positions where exactly one of the bits is set, i.e.
&& is not a binary operation. It simply returns 1 if and only if both operands are non-zero. || returns 1 if and only if at least one of the operands is non-zero. In other cases, they return 0, respectively.
发布评论
评论(1)
十进制1000是二进制111110 1000。十进制255是二进制1111 1111。首先,它们被转换为
签名的int
,通常为32位。服用
&
设置了设置操作数的所有位置的位置:这是十进制的232。服用
|
将在所有位置设置位置至少设置了一位,即IE会产生二进制11111111,即十进制1023。服用^
将在所有位置设置的所有位置设置了其中一个位,即&&
不是二进制操作。仅当两个操作数均不为零时,它才会返回1。||
在且仅当操作数中的至少一个非零时返回1。在其他情况下,它们分别返回0。Decimal 1000 is binary 11 1110 1000. Decimal 255 is binary 1111 1111. First, they are converted to
signed int
, which is usually 32 bits wide.Taking
&
of them sets the bit at all positions where both bits of the operands are set:This is decimal 232. Taking
|
would have set the bit at all positions where at least one bit is set, i.e. would have produced binary 11 1111 1111, which is decimal 1023. Taking^
would have set the bit at all positions where exactly one of the bits is set, i.e.&&
is not a binary operation. It simply returns 1 if and only if both operands are non-zero.||
returns 1 if and only if at least one of the operands is non-zero. In other cases, they return 0, respectively.