Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function BITRSHIFT(number, shift) {
// Return error if either number is a non-numeric value
if (isNaN(number) || isNaN(shift)) return '#VALUE!';
// Return error if number is less than 0
if (number < 0) return '#NUM!';
// Return error if number is a non-integer
if (Math.floor(number) !== number) return '#NUM!';
// Return error if number is greater than (2^48)-1
if (number > 281474976710655) return '#NUM!';
// Return error if the absolute value of shift is greater than 53
if (Math.abs(shift) > 53) return '#NUM!';
// Return number shifted by shift bits to the right or to the left if shift is negative
return (shift >= 0 ) ? number >> shift : number << -shift;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment