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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7e15102eb14c0020 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.73.242 with SMTP id o18mr537169wiv.0.1348942271899; Sat, 29 Sep 2012 11:11:11 -0700 (PDT) Path: q11ni99329727wiw.1!nntp.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!feeder.news.orange.fr!not-for-mail Message-ID: <506739BF.20407@obry.net> Date: Sat, 29 Sep 2012 20:11:11 +0200 From: Pascal Obry Organization: Home - http://www.obry.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR; rv:1.8.1.22) Gecko/20090605 Thunderbird/2.0.0.22 Mnenhy/0.7.5.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada To: Georg Bauhaus Subject: Re: highest bit, statically determined References: <50673111$0$9505$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: <50673111$0$9505$9b4e6d93@newsspool1.arcor-online.net> NNTP-Posting-Date: 29 Sep 2012 20:11:11 CEST NNTP-Posting-Host: 82.124.147.144 X-Trace: 1348942271 reader.news.orange.fr 18064 82.124.147.144:2994 X-Complaints-To: abuse@orange.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Date: 2012-09-29T20:11:11+02:00 List-Id: Georg, > Is there a shorter/better way of having the compiler > find the highest bit = 1 in a static numeric constant? > > If N is such a constant, e.g. Some_Type'Last where > Some_Type'Size = 8 and its bound are static, then > > Highest_Bit_In_Octet : constant := > Natural'Max > (8 * Boolean'Pos (N / 2**7 > 0), > Natural'Max > (7 * Boolean'Pos (N / 2**6 > 0), > Natural'Max > (6 * Boolean'Pos (N / 2**5 > 0), > Natural'Max > (5 * Boolean'Pos (N / 2**4 > 0), > Natural'Max > (4 * Boolean'Pos (N / 2**3 > 0), > Natural'Max > (3 * Boolean'Pos (N / 2**2 > 0), > Natural'Max > (2 * Boolean'Pos (N / 2**1 > 0), > Natural'Max > (1 * Boolean'Pos (N / 2**0 > 0), 0)))))))); if N > 128 then return 8; elsif N > 64 return 7; elsif ... elsif N > 0 then return 1; end if; Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net - http://v2p.fr.eu.org --| "The best way to travel is by means of imagination" --| --| gpg --keyserver keys.gnupg.net --recv-key F949BD3B