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,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 15 Jan 2009 11:29:58 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <496f1027$0$31347$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 15 Jan 2009 11:29:59 CET NNTP-Posting-Host: 0f42072d.newsspool4.arcor-online.net X-Trace: DXC=7ClC`CZTD]e:i=48;n?Z:`4IUK ChristopherL schrieb: > On Jan 14, 12:41 pm, Adam Beneschan wrote: >> Which >> bits do you want to copy? > > The ones containing the mantissa. OK, here is some code to extract the exponent. BTW, consider giving the reference when you quote from Wikipedia. In this case the "general info" seems to have been pasted from http://en.wikipedia.org/wiki/Floating_point#Internal_representation with Interfaces; with Ada.Unchecked_Conversion, Ada.Text_IO; procedure Th is use Ada; Arg: Float; pragma Assert(Float'Size = 32); The_Bits : Interfaces.Unsigned_32; function Just_The_Bits is new Unchecked_Conversion (Source => Float, Target => Interfaces.Unsigned_32); Result: Interfaces.Unsigned_8; package Bit_IO_8 is new Text_IO.Modular_IO (Interfaces.Unsigned_8); package Bit_IO_32 is new Text_IO.Modular_IO (Interfaces.Unsigned_32); begin Arg := 200.0; The_Bits := Just_The_Bits(Arg); Text_IO.Put("starting from float "); Bit_IO_32.Put(The_Bits, Base => 2); Text_IO.Put_Line(" of bit size" & Natural'Image(Float'Size) & ","); Text_IO.Put_Line("for " & Float'Image(Arg) & ", bits 24 .. 31 give"); The_Bits := Interfaces.Shift_Right(The_Bits, 23); Result := Interfaces.Unsigned_8(The_Bits); declare use type Interfaces.Unsigned_8; begin Bit_IO_8.Default_Width := 0; Text_IO.Put("decimal "); Bit_IO_8.Put(Result); Text_IO.Put(", that's "); Bit_IO_8.Put(Result - 127); Text_IO.Put_Line(" without bias"); Text_IO.Put("binary "); Bit_IO_8.Put(Result, Base => 2); Text_IO.Put(", or "); Bit_IO_8.Put(Result - 127, Base => 2); Text_IO.Put_Line(" without bias."); end; end Th;