位运算::Bitwise operation

位运算::Bitwise operation最近学习做 cf 第一题永远都是该死的 Bitwiseopera 好好学习了一下位运算的知识 NOT ThebitwiseNO orbitwisecom isaunaryoper formingtheon complementof Bitsthatare0 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真的好难啊!!!!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/215708.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午1:37
下一篇 2026年3月18日 下午1:37


相关推荐

  • linux下安装tomcat7

    linux下安装tomcat7安装环境LinuxcenterOS6.5tomcat安装(apache-tomcat-7.0.73.tar.gz)Tomca下载地址:http://tomcat.apache.org/download-70.cgi下载后解压:tar-zxvfapache-tomcat-7.0.73.tar.gz建立软连接:ln-sapache-tomcat-7.0.73.tar.gztomcat7设

    2022年5月18日
    45
  • 激动!用DeepSeek赚了4万,手把手分享全栈开发教程!

    激动!用DeepSeek赚了4万,手把手分享全栈开发教程!

    2026年3月15日
    2
  • 如何用C 程序来写一个闰年算法?

    如何用C 程序来写一个闰年算法?我们在小学时老师教我们能被 4 整除的就是闰年 等到我们大了 又有人告诉我们能被 4 整除 但不能被 100 整除的都是闰年 那这是怎么回事 其实 从严格的意义来讲 这两个都不准确 nbsp nbsp nbsp nbsp nbsp 根据维基百科 我们可以知道一标准年为 nbsp nbsp 365 天 5 时 48 分 45 5 秒 nbsp nbsp nbsp nbsp nbsp 那么这就意味着时间存在着人为的误差 由于时间秒的定义是已经规定的标准 不可能改变 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 为了规避这一问

    2026年3月18日
    2
  • Android APK 签名校验[通俗易懂]

    Android APK 签名校验[通俗易懂]非对称加密算法非对称加密算法需要两个密钥:公开密钥(简称公钥)和私有密钥(简称私钥)。公钥与私钥是一对,如果用公钥对数据进行加密,只有用对应的私钥才能解密;如果用私钥对数据进行加密,那么只有用对应的公钥才能解密。因为加密和解密使用的是两个不同的密钥,所以这种算法叫作非对称加密算法。非对称加密算法是数字签名和数字证书的基础,大家非常熟悉的RSA就是非对称加密算法的一种实现。消息摘要算

    2022年5月29日
    424
  • 搞定Prometheus普罗米修斯监控系统

    搞定Prometheus普罗米修斯监控系统学习目录能够安装prometheus服务器 能够通过安装node_exporter监控远程linux 能够通过安装mysqld_exporter监控远程mysql数据库 能够安装grafana 能够在grafana添加prometheus数据源 能够在grafana添加监控cpu负载的图形 能够在grafana图形显示mysql监控数据 能够通过grafana+onealert实现报警任务背景AAA公司是一家电商网站,由于公司的业务快速发展,公司要求对现有机器进行为业务监控,责成运维

    2022年7月19日
    64
  • T-SQL—理解CTEs

    T-SQL—理解CTEs

    2021年11月26日
    57

发表回复

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

关注全栈程序员社区公众号