lynnjyu
V2EX  ›  问与答

想请教下关于异或运算

  •  
  •   lynnjyu · Feb 22, 2019 · 1596 views
    This topic created in 2662 days ago, the information mentioned may be changed or developed.

    在 java 中 2518379987 ^ 0 得到的是 2518379987

    但是在 js 中我尝试着用 2518379987 ^ 0 运算得到结果 -1776587309

    为什么会有这两种不同的结果呢?

    4 replies    2019-02-22 17:50:28 +08:00
    ballshapesdsd
        1
    ballshapesdsd  
       Feb 22, 2019
    补码吧,变成有符号 int 了?
    yukiww233
        2
    yukiww233  
       Feb 22, 2019
    GPIO
        3
    GPIO  
       Feb 22, 2019   ❤️ 1
    int x=2518379987;
    unsigned int x1=2518379987;
    int x2=x^0;
    unsigned int x3=x1^0;
    std::cout << x2 << " " << x3 << endl;

    输出 -1776587309 2518379987
    hahastudio
        4
    hahastudio  
       Feb 22, 2019
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
    The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   933 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 22:40 · PVG 06:40 · LAX 15:40 · JFK 18:40
    ♥ Do have faith in what you're doing.