Compute modulus division by a power | Java code for Compute modulus division by a power - of - 2 - number ; 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
class GFG { static int getModulo ( int n , int d ) { return ( n & ( d - 1 ) ) ; } public static void main ( String [ ] args ) { int n = 6 ; int d = 4 ; System . out . println ( n + " ▁ moduo ▁ " + d + " ▁ is ▁ " + getModulo ( n , d ) ) ; } }