public N getEnclosingNetwork(int mask) throws NetworkException {
        if ((mask < 0) || (mask > 1)) {
            throw new InvalidAddressException(String.format("'%d' is not a valid netmask.", mask));
        }
        if (mask > longMaskToShort(this.mask)) {
            throw new InvalidAddressException(String.format("Network '%s' cannot be contained in a /%d network.", toString(), mask));
        }
        BigInteger longMask = shortMaskToLong(mask);
        BigInteger addr = address.and(longMask);
        return newNetwork(addr, longMask);
    }