aboutsummaryrefslogtreecommitdiffstats
path: root/src/zlsb.c
blob: 17012f84f8341b42a731ed5a1ebe9265da4831dd (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.h"


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;
		}
	}
}