Compute modulus division by a power | This function will return n % d . d must be one of : 1 , 2 , 4 , 8 , 16 , 32 , ... ; Driver Code ; d must be a power of 2
function getModulo ( n , d ) { return ( n & ( d - 1 ) ) ; } n = 6 ; d = 4 ; document . write ( n + " " + d + " " + getModulo ( n , d ) ) ;