Forum > Beginners

simple problem: count digits of number

<< < (9/9)

MathMan:
Hm, looking through the RTL I do see - BsrQWord, BsrDWord, BsrWord.

Looking at generated asm they do indeed produce a BSR instruction (on x86 of course) plus a check for value=0.

They unfortunately return 255 for value=0. However the last can easily be circumvented in this case by e.g. BsrQWord( value or 1 ).

The implementations shown in the linked blog-post of Daniel Lemire can more or less directly be translated to Pascal. If I remember correct then engkin related to a precursor of this approach already during the discussions in 2018. ;-)

Cheers,
MathMan

Bart:
Changed it into:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function LeadingZeroBits(n: QWORD; BitSize: Integer): Integer;begin  if (n = 0) then    Exit(BitSize);  Result := BitSize - 1 {%H-}- BsrQWORD(n);end;/code] Bart

Navigation

[0] Message Index

[*] Previous page

Go to full version