private IPAddress computeMaskFromNetworkPrefix ( int prefix ) { /* * int subnet = 0; for (int i=0; i<prefix; i++) { subnet = subnet << 1; subnet += 1; } */ StringBuilder str = new StringBuilder ( ) ; for ( int i = 0 ; i < 32 ; i ++ ) { if ( i < prefix ) { str . append ( "1" ) ; } else { str . append ( "0" ) ; } } String decimalString = toDecimalString ( str . toString ( ) ) ; return new IPAddress ( decimalString ) ; }
Convert a extended network prefix integer into an IP number .