public static int prefixLengthToNetmaskInt(int prefixLength) throws IllegalArgumentException {
  if (prefixLength < 0 || prefixLength > 32) {
    throw new IllegalArgumentException("Invalid prefix length (0 <= prefix <= 32)");
  }
  int value=0xffffffff << (32 - prefixLength);
  return Integer.reverseBytes(value);
}

public static int prefixLengthToNetmaskInt ( int prefixLength ) throws IllegalArgumentException { if ( prefixLength < 0 || prefixLength > 32 ) { throw new IllegalArgumentException ( "Invalid prefix length (0 <= prefix <= 32)" ) ; } int value = 0xffffffff << ( 32 - prefixLength ) ; return Integer . reverseBytes ( value ) ; }
convert a network prefix length to an ipv4 netmask integer
