欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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>