码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 位运算::Bitwise operation


    最近学习做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:

    A 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:

    A 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

    A 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真的好难啊!!!!

  • 相关阅读:
    打靶笔记-03-vulnhub-Moriarty Corp
    Neovim 配置全面解析(下)
    【1024社区大奖】助你狂揽大奖[保姆级教程①]
    软件测试工具有什么作用?有哪些好用的测试工具推荐?
    GO实现Redis:GO实现Redis集群(5)
    mysql的缓存页对LRU的改进;预读机制;及对应的调优
    J9数字论:模块化公链能否成为公链新趋势?
    DP:解决路径问题
    【JavaScript】js判断一个变量是数组
    【论文复现|智能算法改进】融合正余弦策略的算术优化算法
  • 原文地址:https://blog.csdn.net/beloved_yu/article/details/125514616
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号