lynnjyu
V2EX  ›  问与答

想请教下关于异或运算

  •  
  •   lynnjyu · Feb 22, 2019 · 1925 views
    This topic created in 2834 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
    ballshapesdsd
    Feb 22, 2019
    1
    补码吧,变成有符号 int 了?
    yukiww233
    yukiww233
    Feb 22, 2019
    2
    GPIO
    GPIO
    Feb 22, 2019❤️1
    3
    int x=2518379987;
    unsigned int x1=2518379987;
    int x2=x^0;
    unsigned int x3=x1^0;
    std::cout << x2 << " " << x3 << endl;

    输出 -1776587309 2518379987
    hahastudio
    hahastudio
    Feb 22, 2019
    4
    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   ·   Privacy   ·   Solana   ·   968 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:40 · PVG 03:40 · LAX 11:40 · JFK 14:40
    ♥ Do have faith in what you're doing.