diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-04-28 12:38:03 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2011-04-29 12:31:10 +0200 |
commit | db7c11768a968913c783c05c27e06bcf249502c0 (patch) | |
tree | a81d685d86ce87d4ebebae14e3fc0878e3dc1fd0 /src/mm-utils.c | |
parent | a0c902bdb5f03fc4d4b58ffbfb8bb36c06bfa55f (diff) |
utils: new utils_check_for_single_value() method
It was being used in several places with different static implementations
Diffstat (limited to 'src/mm-utils.c')
-rw-r--r-- | src/mm-utils.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mm-utils.c b/src/mm-utils.c index c435d1d6..236c2d9f 100644 --- a/src/mm-utils.c +++ b/src/mm-utils.c @@ -90,3 +90,20 @@ utils_bin2hexstr (const guint8 *bin, gsize len) return g_string_free (ret, FALSE); } +gboolean +utils_check_for_single_value (guint32 value) +{ + gboolean found = FALSE; + guint32 i; + + for (i = 1; i <= 32; i++) { + if (value & 0x1) { + if (found) + return FALSE; /* More than one bit set */ + found = TRUE; + } + value >>= 1; + } + + return TRUE; +} |