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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.uni-weimar.de!medsec1.medien.uni-weimar.de!lucks From: Stefan.Lucks@uni-weimar.de Newsgroups: comp.lang.ada Subject: Re: Efficient Bit Vector Manipulation. Date: Mon, 18 May 2015 09:53:09 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <62605fe5-6ecf-4750-b13c-24bce65e3439@googlegroups.com> NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1630194333-1431935593=:30700" X-Trace: pinkpiglet.scc.uni-weimar.de 1431936004 9356 141.54.178.228 (18 May 2015 08:00:03 GMT) X-Complaints-To: news@pinkpiglet.scc.uni-weimar.de NNTP-Posting-Date: Mon, 18 May 2015 08:00:03 +0000 (UTC) X-X-Sender: lucks@debian In-Reply-To: <62605fe5-6ecf-4750-b13c-24bce65e3439@googlegroups.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) Xref: news.eternal-september.org comp.lang.ada:25898 Date: 2015-05-18T09:53:09+02:00 List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1630194333-1431935593=:30700 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 15 May 2015, Vincent wrote: > I need to extract in a very efficient way, information from the bit=20 > sequence that represents a 32 bits Positive number, named=A0I > 0. A good way to represent a 32-bit Positive number may be type Int is mod 2**32; > - find the length of the bit sequence, i.e. the number of bits a given=20 [...] > For instance : > - I =3D 1 is represented by 1 and k =3D 0. > - I =3D 2 is represented by 10 and k =3D 1. > - I =3D 3 is represented by 11 and k =3D 1. > - I =3D 4 is represented by 100 and k =3D 2. 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 :=3D 0; Value: Int :=3D I; begin while Value > 1 loop =09 Result :=3D Result + 1; =09 Value :=3D Value / 2; end loop; return Result; end Significant_Bits; > Then I would like to : > - extract the b =3D floor(k/2) bits leading the first 1 starting from MSB= and convert them to an integer : B > - extract the remaining e =3D Ceiling (k/2) bits and convert them to an i= nteger :=A0E. > > then I =3D 2^k + B * 2^b + E This looks like a homework problem -- so I will not give you a complete=20 solution. But the above should give you a good start. Stefan. ------ I love the taste of Cryptanalysis in the morning! ------ uni-weimar.de/de/medien/professuren/mediensicherheit/people/stefan-lucks --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universit=E4t Weimar, Germany-- --8323329-1630194333-1431935593=:30700--