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


size_t
zlsb(z_t a)
{
	size_t i = 0;
	zahl_char_t x;
	if (zzero(a))
		return SIZE_MAX;
	for (;; i++) {
		x = a->chars[i];
		if (x) {
			x = ~x;
			for (i *= BITS_PER_CHAR; x & 1; x >>= 1, i++);
			return i;
		}
	}
}