code: public static int netmaskToPrefix(InetAddress netmask)
  	{
  		byte[] mask = netmask.getAddress();
  
  		if (!isValidNetmask(mask))
  			throw new IllegalArgumentException("Not a valid netmask: " + netmask.getHostAddress());
  
  		int prefix = 0;
  		for (int i = 0; i < mask.length; i++)
  		{
  			// drops-through all lower cases to accumulate additions (so case: -2 becomes prefix += 7)
  			switch (mask[i])
  			{
  				case -1:
  					prefix += 8; // Hand-optimisation for a 255 segment (since it's so frequent)
  					break;
  				case -2:
  					prefix++;
  				case -4:
  					prefix++;
  				case -8:
  					prefix++;
  				case -16:
  					prefix++;
  				case -32:
  					prefix++;
  				case -64:
  					prefix++;
  				case -128:
  					prefix++;
  				default:
  			}
  		}
  
  		return prefix;
  	}
docs: Determines the prefix for a given netmask (ie. turns 255.255.255.0 into 24)<br />
  Returns the number of contiguous 1 bits. Throws an IllegalArgumentException if the address is an invalid netmask
  
  @param netmask
  An IP netmask (eg. 255.255.252.0)
  
  @return A prefix length (the number of 1-bits in the netmask)
  
  @throws IllegalArgumentException
  if an invalid netmask is passed