public static String cidrMaskToNetMask(String cidrMask){
  if (cidrMask == null) {
    return null;
  }
  int cidrMaskValue=0;
  try {
    cidrMaskValue=Integer.parseInt(cidrMask);
  }
 catch (  NumberFormatException e) {
    return null;
  }
  int cidrMaskFull=0xffffffff << (32 - cidrMaskValue);
  int cidrMaskBits1=cidrMaskFull >> 24 & 0xff;
  int cidrMaskBits2=cidrMaskFull >> 16 & 0xff;
  int cidrMaskBits3=cidrMaskFull >> 8 & 0xff;
  int cidrMaskBits4=cidrMaskFull >> 0 & 0xff;
  StringBuffer netMaskBuf=new StringBuffer();
  netMaskBuf.append(cidrMaskBits1);
  netMaskBuf.append('.');
  netMaskBuf.append(cidrMaskBits2);
  netMaskBuf.append('.');
  netMaskBuf.append(cidrMaskBits3);
  netMaskBuf.append('.');
  netMaskBuf.append(cidrMaskBits4);
  return netMaskBuf.toString();
}

public static String cidrMaskToNetMask ( String cidrMask ) { if ( cidrMask == null ) { return null ; } int cidrMaskValue = 0 ; try { cidrMaskValue = Integer . parseInt ( cidrMask ) ; } catch ( NumberFormatException e ) { return null ; } int cidrMaskFull = 0xffffffff << ( 32 - cidrMaskValue ) ; int cidrMaskBits1 = cidrMaskFull > > 24 & 0xff ; int cidrMaskBits2 = cidrMaskFull > > 16 & 0xff ; int cidrMaskBits3 = cidrMaskFull > > 8 & 0xff ; int cidrMaskBits4 = cidrMaskFull > > 0 & 0xff ; StringBuffer netMaskBuf = new StringBuffer ( ) ; netMaskBuf . append ( cidrMaskBits1 ) ; netMaskBuf . append ( '.' ) ; netMaskBuf . append ( cidrMaskBits2 ) ; netMaskBuf . append ( '.' ) ; netMaskBuf . append ( cidrMaskBits3 ) ; netMaskBuf . append ( '.' ) ; netMaskBuf . append ( cidrMaskBits4 ) ; return netMaskBuf . toString ( ) ; }
transforms a cidr formatted mask into a regular network mask
