aboutsummaryrefslogtreecommitdiffstats
path: root/src/zbits.c
blob: 8ada62f236b640ebf107c46c0a2135770f7f8d31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* See LICENSE file for copyright and license details. */
#include "internals"


size_t
zbits(z_t a)
{
	size_t i;
	zahl_char_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;
		}
	}
}