def _get_masked_bits(mask):
 if (not is_valid_ipv4_address(mask)):
  raise ValueError(("'%s' is an invalid subnet mask" % mask))
 mask_bin = _get_address_binary(mask)
 mask_match = re.match('^(1*)(0*)$', mask_bin)
 if mask_match:
  return (32 - len(mask_match.groups()[1]))
 else:
  raise ValueError(('Unable to convert mask to a bit count: %s' % mask))

def _get_masked_bits ( mask ) : if ( not is_valid_ipv4_address ( mask ) ) : raise ValueError ( ( "'%s' is an invalid subnet mask" % mask ) ) mask_bin = _get_address_binary ( mask ) mask_match = re . match ( '^(1*)(0*)$' , mask_bin ) if mask_match : return ( 32 - len ( mask_match . groups ( ) [ 1 ] ) ) else : raise ValueError ( ( 'Unable to convert mask to a bit count: %s' % mask ) )
provides the number of bits that an ipv4 subnet mask represents .