Skip to content

Instantly share code, notes, and snippets.

@bmeck
Created August 17, 2010 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/532479 to your computer and use it in GitHub Desktop.
Save bmeck/532479 to your computer and use it in GitHub Desktop.
function andOp(x,y) {
var xchunks=[],ychunks=[];
while(x>0xffffffff){xchunks.push(x|0);x=(x/0x100000000)|0}
xchunks.push(x|0);x=(x/0x100000000)|0
while(y>0xffffffff){ychunks.push(y|0);y=(y/0x100000000)|0}
ychunks.push( y|0); y=(y/0x100000000)|0
//dont need to test lengths
var result = 0
for(var i=ychunks.length-1;i>=0;i--) {
var chunk = ychunks[i]
result += (chunk & xchunks[i]) | 0
console.log([chunk,xchunks[i],result])
if(i>0) {
result *= 0x100000000
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment