modem-helpers: new helper to count number of bits set in a bitmask

This commit is contained in:
Aleksander Morgado
2011-12-02 09:55:39 +01:00
parent a181b152a1
commit 3dcdc3c920
2 changed files with 12 additions and 0 deletions

View File

@@ -1441,3 +1441,13 @@ done:
return array; return array;
} }
guint
mm_count_bits_set (gulong number)
{
guint c;
for (c = 0; number; c++)
number &= number - 1;
return c;
}

View File

@@ -92,4 +92,6 @@ gint cind_response_get_max (CindResponse *r);
GByteArray *mm_parse_cind_query_response(const char *reply, GError **error); GByteArray *mm_parse_cind_query_response(const char *reply, GError **error);
guint mm_count_bits_set (gulong number);
#endif /* MM_MODEM_HELPERS_H */ #endif /* MM_MODEM_HELPERS_H */