7 #include "cln/integer.h"
18 // Sei n = ord2(x). Dann ist logxor(x,x-1) = 2^n + (2^n-1) = 2^(n+1)-1.
19 // Also (ord2 x) = (1- (integer-length (logxor x (1- x)))) .
21 // Sei n = ord2(x). Dann ist logand(x,-x) = 2^n.
22 // Also (ord2 x) = (1- (integer-length (logand x (- x)))) .
24 // Sei n = ord2(x). Dann ist lognot(logior(x,-x)) = 2^n-1.
25 // Also (ord2 x) = (integer-length (lognot (logior x (- x)))) .
27 // Nullbits am Schluß von x abzählen:
28 // (ord2 x) = intDsize * Anzahl der Nulldigits am Schluß
29 // + Anzahl der Nullbits am Ende des letzten Digits /=0.
31 uintL ord2 (const cl_I& x) // x /= 0
34 { var uintV x_ = FN_to_V(x); // x als intVsize-Bit-Zahl
35 // This assumes cl_value_len <= intVsize.
43 { var uintL bitcount = 0;
45 BN_to_NDS_nocopy(x, ,,ptr=); // normalisierte DS zu x bilden.
46 while (lspref(ptr,0) == 0) { lsshrink(ptr); bitcount += intDsize; } // Nulldigits abzählen
47 var uintD lsd = lspref(ptr,0); // letztes Digit /=0
48 ord2_D(lsd,bitcount +=); // dessen Nullbits abzählen