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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f9957894e0bdf128 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 14 Jan 2009 15:41:29 -0600 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: How to put 200 into an integer sub-type of 16 bits (code included) Date: Wed, 14 Jan 2009 21:51:02 +0000 Reply-To: brian@shapes.demon.co.uk Message-ID: <4gksm459vjb82fj4giksdfofls9iltlttm@4ax.com> References: <407ae64d-3cb3-4310-b59e-f1bbae9910a5@t39g2000prh.googlegroups.com> <71gqm49eatq868htrvd7eghm3m8su8kcbl@4ax.com> <3d3719f4-355c-4094-9902-495d612d46fe@n33g2000pri.googlegroups.com> <139961e9-bae6-4e60-8ff7-4f4779b27481@z6g2000pre.googlegroups.com> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-yaaiQtlakB84228+u7QAXKCe+GGkQurx5o01qr0hZ5q7WpletlygcZgJjm1UNfCHy/Lbda73h0zudGY!juDFlvSMjcPUT8cJLizJgdQZp62EMZ06RSPCixxCvoPAKcJpIpO+JlCgAEtyGNC3UEgcu5XidupR!zkiT X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Xref: g2news2.google.com comp.lang.ada:4273 Date: 2009-01-14T21:51:02+00:00 List-Id: On Wed, 14 Jan 2009 12:13:29 -0800 (PST), ChristopherL wrote: > >I want to copy bits from an Ada float to a user defined short integer >maintaining the same >bit representation. FROM a Float? This is the first time you have said that. Now - assuming SP float, which bits? You have 32 to choose from, and you alternate between wanting 16 bits (last time) and 8 bits (as here). But you still ha you want: (a) the top 8 bits? (b) the bottom 8 bits? (c) the exponent? (d) the top 8 bits of the mantissa, (e) an integer representation (200) of the input Float _value_ (200.0) instead of its _bit_pattern_ (f) something else altogether > >Arg:Float; -- From this with a value of 200 >subtype Short_integer is Integer range -(2 ** 7) .. ((2 ** 7) - 1 ); >Result: Short_integer; --to this, and I want to round Arg If (e) you have 2 options: (1) for 8 bits you need an unsigned integer, e.g. subtype Short_integer is Natural range 0 .. ((2 ** 8) - 1 ); (2) for 16 bits, either signed or unsigned will work. subtype Short_integer is Integer range -(2 ** 15) .. ((2 ** 15) - 1 ); In either case, all you need is Result: Short_integer := Short_integer(Arg + 0.5); Of course it may well round up to 201... - Brian