Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created Jan 8, 2013
Embed
What would you like to do?
BITAND Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITAND(number1, number2) {
// Return error if either number is a non-numeric value
if (isNaN(number1) || isNaN(number2)) return '#VALUE!';
// Return error if either number is less than 0
if (number1 < 0 || number2 < 0) return '#NUM!';
// Return error if either number is a non-integer
if (Math.floor(number1) !== number1 || Math.floor(number2) !== number2) return '#NUM!';
// Return error if either number is greater than (2^48)-1
if (number1 > 281474976710655 || number2 > 281474976710655) return '#NUM!';
// Return bitwise AND of two numbers
return number1 & number2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment