public static int multiplyToShift ( int a ) { if ( a < 1 ) { throw new IllegalArgumentException ( "Multiplicand must be at least 1" ) ; } int shift = 31 - Integer . numberOfLeadingZeros ( a ) ; if ( ( 1 << shift ) != a ) { throw new IllegalArgumentException ( "Multiplicand must be a power of 2" ) ; } return shift ; }
Converts a multiplication into a shift .