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