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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no 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.105.2 with SMTP id gi2mr557040wib.4.1348945184422; Sat, 29 Sep 2012 11:59:44 -0700 (PDT) Path: q10ni30507477wif.0!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!195.71.90.67.MISMATCH!news.unit0.net!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 29 Sep 2012 20:59:43 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: highest bit, statically determined References: <50673111$0$9505$9b4e6d93@newsspool1.arcor-online.net> <506739BF.20407@obry.net> In-Reply-To: <506739BF.20407@obry.net> Message-ID: <5067451f$0$9524$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Sep 2012 20:59:43 CEST NNTP-Posting-Host: 7fe2a8de.newsspool1.arcor-online.net X-Trace: DXC=F\PQQYYES1lj5k5aEF7ISmic==]BZ:afn4Fo<]lROoRankgeX?EC@@`USa^hhA5AYjPCY\c7>ejVhNH>negGeW]h\gjg1hD9?Lj X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-09-29T20:59:43+02:00 List-Id: On 29.09.12 20:11, Pascal Obry wrote: >> Highest_Bit_In_Octet : constant := >> Natural'Max >> (8 * Boolean'Pos (N / 2**7 > 0), ... >> (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; > The N > 2**X part is good, thanks for the answer that removed a fair bit of fog. But the "return X" indicates that the solution cannot be static, or can it? There might be an expression in Ada 2012 that does it. Alas, I cannot use Ada 2012 yet---which I should have mentioned! Highest_Bit_In_Octet_2012 : constant := (if N > 2**7 then 8 elsif N > 2**6 then 7 elsif N > 2**5 then 6 elsif N > 2**4 then 5 elsif N > 2**3 then 4 elsif N > 2**2 then 3 elsif N > 2**1 then 2 elsif N > 2**0 then 1 else 0);