位运算::Bitwise operation

位运算::Bitwise operation最近学习做cf,第一题永远都是该死的Bitwiseoperation,好好学习了一下位运算的知识。NOT:ThebitwiseNOT,orbitwisecomplement,isaunaryoperationthatperformslogicalnegationoneachbit,formingtheones’complementofthegivenbinaryvalue.Bitsthatare0become1,andthosethat

最近学习做cf,第一题永远都是该死的Bitwise operation,好好学习了一下位运算的知识。

NOT:

The bitwise NOT, or bitwise complement, is a unary operation that performs logical negation on each bit, forming the ones’ complement of the given binary value. Bits that are 0 become 1, and those that are 1 become 0. For example:

按位 NOT按位补码是一元运算,它对每个位执行逻辑否定,形成给定二进制值的反码。为 0 的位变为 1,为 1 的位变为 0。例如:

NOT 0111  (decimal 7)
  = 1000  (decimal 8)

其实也就是,按二进制展开以后对每一位数字进行一个取反的操作。

结果是二进制的补码再减去一:NOT x = -x − 1.

AND:

bitwise AND is a binary operation that takes two equal-length binary representations and performs the logical AND operation on each pair of the corresponding bits. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1 × 1 = 1); otherwise, the result is 0 (1 × 0 = 0 and 0 × 0 = 0). For example:

   0101 (decimal 5)
AND 0011 (decimal 3)
  = 0001 (decimal 1)

也就是说,同一取一,10取0, 00取0.

OR:

bitwise OR is a binary operation that takes two bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits. The result in each position is 0 if both bits are 0, while otherwise the result is 1. For example:

   0101 (decimal 5)
OR 0011 (decimal 3)
 = 0111 (decimal 7)

只要有一个1就是1.

XOR

bitwise XOR is a binary operation that takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is 1 if only one of the bits is 1, but will be 0 if both are 0 or both are 1. In this we perform the comparison of two bits, being 1 if the two bits are different, and 0 if they are the same. For example:

    0101 (decimal 5)
XOR 0011 (decimal 3)
  = 0110 (decimal 6)

只要两个数不同就取1,相同的话就取0.

cf真的好难啊!!!!

今天的文章位运算::Bitwise operation分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/4881.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注