jx99
V2EX  ›  Java

请教个负数按位或运算的问题

  •  
  •   jx99 · Oct 29, 2018 · 3536 views
    This topic created in 2780 days ago, the information mentioned may be changed or developed.

    在复习的时候看到基本运算,自己随便定义了几题,然后发现-7 | 11 通过程序运算出来得到的是-5,自己怎么算都算不出来-5.

    3 replies    2018-10-30 10:02:27 +08:00
    jx99
        1
    jx99  
    OP
       Oct 29, 2018
    nroskill
        2
    nroskill  
       Oct 29, 2018
    -7 == 11...11001
    11 == 00...01011
    所以
    -7 | 11 = 11...11011 == -5
    如果不明白,建议翻阅资料 补码
    98jiang
        3
    98jiang  
       Oct 30, 2018
    -7 补码 11111001
    11 补码 00001011
    或运算得到补码 11111011
    逐位取反为:00000100 二进制数+1 得:0000101
    加上负号,结果为-5
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1344 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 17:15 · PVG 01:15 · LAX 10:15 · JFK 13:15
    ♥ Do have faith in what you're doing.