大值的按位或

Bitwise OR on Large Values

我需要对大数进行按位运算。

例如:

2 | 2147483648

我希望 2147483650,但得到 -2147483646

这是为什么,我该怎么办?

请注意,我正在处理的代码是一些旧的 javascript 代码,它是经典 asp 中的 运行 服务器端代码,我认为它是旧版本的 js

我找到了解决方法。

您可以使用 BigInteger.js 库稍作修改,以便在带有 Classic ASP 的服务器端 JS 中使用。

https://raw.githubusercontent.com/peterolson/BigInteger.js/master/BigInteger.js

要在经典 asp 中使用,请执行以下操作:

修改 BigInteger.js 库的第 21 行和第 28 行,使其可以在服务器端使用经典 ASP:

更改第 21 行:

BigInteger.prototype = Object.create(Integer.prototype);

收件人:

BigInteger.prototype = new Object(Integer.prototype);

并对第 28 行进行相同的更改。

然后,删除最后 4 行。不需要它们:

// Node.js check
if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
    module.exports = bigInt;
}

然后在你的脚本中像这样包含它:

<script language="javascript" runat="server">

... the bigInteger.js code... 

function bitOrJS(a, b) {
    var big = new bigInt(a);

    return big.or(b);

}
</script>

您现在可以使用经典ASP vbscript 代码中的函数:

Dim result

result = bitOrJS(2147483648, 2)

response.write result

输出将如预期的那样 2147483650