diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-01 18:37:05 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-01 18:37:05 +0100 |
| commit | b0c1cae18066d0103a440894b5256939852021eb (patch) | |
| tree | b90f419aba218eedf1cc664c7269666306e6ccaf /src/zbits.c | |
| parent | Add .gitignore (diff) | |
| download | libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.gz libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.bz2 libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.xz | |
Add zsetup, zunsetup, zinit, zfree, zswap, zsave, zload, zbits, and zlsb
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zbits.c')
| -rw-r--r-- | src/zbits.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zbits.c b/src/zbits.c new file mode 100644 index 0000000..07c1591 --- /dev/null +++ b/src/zbits.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +#include "internals" + + +size_t +zbits(z_t a) +{ + size_t i; + uint32_t x; + if (zzero(a)) { + return 1; + } + for (i = a->used - 1;; i--) { + x = a->chars[i]; + if (x) { + a->used = i + 1; + for (i *= BITS_PER_CHAR; x; x >>= 1, i++); + return i; + } + } +} |
