class NetUtils {

    public static int getSubnetMaskLength(byte[] subnetMask) {
        int maskLength = 0;
        if (subnetMask != null && (subnetMask.length == 4 || subnetMask.length == 16)) {
            int index = 0;
            while (index < subnetMask.length && subnetMask[index] == (byte) 0xFF) {
                maskLength += NetUtils.NUM_BITS_IN_A_BYTE;
                index++;
            }
            if (index != subnetMask.length) {
                int bits = NetUtils.NUM_BITS_IN_A_BYTE - 1;
                while (bits >= 0 && (subnetMask[index] & 1 << bits) != 0) {
                    bits--;
                    maskLength++;
                }
            }
        }
        return maskLength;
    }

    private  NetUtils();

}