public static InetAddress subnetAddress0(InetAddress addr, int subnetBits) {
    if (subnetBits < 1 || 32 <= subnetBits) {
      throw new FireRESTException("Expected subnetBits 1..31");
    }
    long mask = 1;
    for (int i = 0; i < 32; i++) {
      mask <<= 1;
      mask |= i < subnetBits ? 1 : 0;
    }
    long host0 = asLongAddress(addr) & mask;
    try {
      return asInetAddress(host0);
    } catch (UnknownHostException e) {
      throw new FireRESTException(e);
    }
  }
public static InetAddress subnetAddress0(InetAddress addr, int subnetBits) {
    if (subnetBits < 1 || 32 <= subnetBits) {
      throw new FireRESTException("Expected subnetBits 1..31");
    }
    long mask = 1;
    for (int i = 0; i < 32; i++) {
      mask <<= 1;
      mask |= i < subnetBits ? 1 : 0;
    }
    long host0 = asLongAddress(addr) & mask;
    try {
      return asInetAddress(host0);
    } catch (UnknownHostException e) {
      throw new FireRESTException(e);
    }
  }
public static InetAddress subnetAddress0 ( InetAddress addr , int subnetBits ) { if ( subnetBits < 1 || 32 <= subnetBits ) { throw new FireRESTException ( "Expected subnetBits 1..31" ) ; } long mask = 1 ; for ( int i = 0 ; i < 32 ; i ++ ) { mask <<= 1 ; mask |= i < subnetBits ? 1 : 0 ; } long host0 = asLongAddress ( addr ) & mask ; try { return asInetAddress ( host0 ) ; } catch ( UnknownHostException e ) { throw new FireRESTException ( e ) ; } }
Return first address on subnet containing given address

@param addr any machine in subnet
@param subnetBits the number of bits in subnet mask. Many small networks use 24.
@return first address on subnet. E.g., subnetAddress(10.0.1.88, 25) -> 10.0.1.0
Return first address on subnet containing given address