javascript 实现超过32位数与运算
程序员文章站
2022-05-10 18:22:34
...
<script type="text/javascript">
var a = 146028888064;
var b = 8589934592;
var c = 8589934592;
var d = 4294967296;
var sd = 2147483648
function optionor() {
var barr = toBin(b);
var aarr = toBin(a);
var rearr = [];
var result = 0;
var power = 1;
for (var i = 0; i < barr.length; i++) {
result += (barr[i] & aarr[i])*power;
power = power*65536;
}
alert(result);
}
function toBin(intNum) {
var answer = [];
if(/\d+/.test(intNum)) {
while(intNum != 0) {
answer[answer.length]=Math.abs(intNum%65536);
intNum = parseInt(intNum/65536);
}
if(answer.length == 0){
answer = [0];
}
return answer;
} else {
return [0];
}
}
</script>
var a = 146028888064;
var b = 8589934592;
var c = 8589934592;
var d = 4294967296;
var sd = 2147483648
function optionor() {
var barr = toBin(b);
var aarr = toBin(a);
var rearr = [];
var result = 0;
var power = 1;
for (var i = 0; i < barr.length; i++) {
result += (barr[i] & aarr[i])*power;
power = power*65536;
}
alert(result);
}
function toBin(intNum) {
var answer = [];
if(/\d+/.test(intNum)) {
while(intNum != 0) {
answer[answer.length]=Math.abs(intNum%65536);
intNum = parseInt(intNum/65536);
}
if(answer.length == 0){
answer = [0];
}
return answer;
} else {
return [0];
}
}
</script>
下一篇: 人力资源管理案例-左右为难的经理
推荐阅读
-
Javascript与jQuery方法的隐藏与显示实现方法
-
用Json实现PHP与JavaScript间数据交换的方法详解_PHP
-
IOS ObjectC与javascript交互详解及实现代码
-
Android编程使用WebView实现与Javascript交互的方法【相互调用参数、传值】
-
JS实现集合的交集、补集、差集、去重运算示例【ES5与ES6写法】
-
javascript使用substring实现的展开与收缩文字功能示例
-
JavaScript实现简单的四则运算计算器完整实例
-
Android编程使用WebView实现与Javascript交互的方法【相互调用参数、传值】
-
PHP与javascript实现变量交互的示例代码
-
实现高性能JavaScript之执行与加载