From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.186.15 with SMTP id cq15mr47663208icb.34.1431949431918; Mon, 18 May 2015 04:43:51 -0700 (PDT) X-Received: by 10.140.48.11 with SMTP id n11mr294428qga.35.1431949431848; Mon, 18 May 2015 04:43:51 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!j8no4480143igd.0!news-out.google.com!k20ni30387qgd.0!nntp.google.com!z60no1800501qgd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 18 May 2015 04:43:51 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=185.30.132.97; posting-account=hya6vwoAAADTA0O27Aq3u6Su3lQKpSMz NNTP-Posting-Host: 185.30.132.97 References: <62605fe5-6ecf-4750-b13c-24bce65e3439@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <110bca30-dd79-4c8d-8a3f-8c39a2e24688@googlegroups.com> Subject: Re: Efficient Bit Vector Manipulation. From: vincent.diemunsch@gmail.com Injection-Date: Mon, 18 May 2015 11:43:51 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:25903 Date: 2015-05-18T04:43:51-07:00 List-Id: > The following should give you the k you ask for: > > type Position_Type is range 0 .. 32; > > function Significant_Bits(I: Int) return Position_Type is > Result: Position_Type := 0; > Value: Int := I; > begin > while Value > 1 loop > Result := Result + 1; > Value := Value / 2; > end loop; > return Result; > end Significant_Bits; > Thank you Stephan. This is indeed the obvious solution. There are much faster ones on the site given by Niklas.