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,f9957894e0bdf128 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: How to put 200 into an integer sub-type of 16 bits (code included) 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> <87816592-c947-4bbc-92ed-7473646a105e@a12g2000pro.googlegroups.com> <1a2b31ac-cf6b-44e3-85b7-04594460db87@d36g2000prf.googlegroups.com> From: Stephen Leake User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Date: Thu, 15 Jan 2009 09:02:34 -0500 Message-ID: <86ab9s7jlx.fsf@stephe-leake.org> Cancel-Lock: sha1:/5JJi3cku4o9vlaFG75R8uGi1kU= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: cd50f496f4205c77fb68819078 Xref: g2news2.google.com comp.lang.ada:4292 Date: 2009-01-15T09:02:34-05:00 List-Id: ChristopherL writes: > On Jan 14, 12:41 pm, Adam Beneschan wrote: >> On Jan 14, 12:13 pm, ChristopherL wrote: >> >> > I want to copy bits from an Ada float to a user defined short integer >> > maintaining the same >> > bit representation. >> > > This problem was given to me to try to solve who said it's probably > impossible! Ok. This could eventually be used to verify the floating point format used by your machine, for example. The right way to proceed is to write a bit-level record clause for the floating point type on your hardware; something like: type unsigned_24 is ...; type usigned_7 is ...; type IEEE_32_Float_Rep_Type is record sign : boolean; exponent : unsigned_7; mantissa_1 : Interfaces.unsigned_8; mantissa_2 : Interfaces.unsigned_8; mantissa_3 : Interfaces.unsigned_8; end record; for IEEE_32_Float_Rep_Type use record sign : at 0 range 0 .. 0; exponent : at 0 range 1 .. 8; mantissa_1 : at 0 range 9 .. 15; mantissa_2 : at 0 range 16 .. 23; mantissa_3 : at 0 range 24 .. 31; end record; Note that I broke the mantissa down into three parts, each fitting in 8 bits. I probably have the details wrong for IEEE 32 bit float; look it up somewhere. Especially note that the 'range' values need to have the correct endianness for your machine (sign will be at 31 on some machines, 0 on others). Then use unchecked conversion from float to IEEE_32_Float_Rep_type, then simple assignment (possibly with an integer type conversion) from any field to an Unsigned_8. -- -- Stephe