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,f3514db0a21f9b44 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!q31g2000prf.googlegroups.com!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Hexadecimal and stream element arrays Date: Mon, 19 Apr 2010 16:34:32 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <2f4313a5-bb3d-4f7f-8a86-7c8f7d549c53@k41g2000yqf.googlegroups.com> <90efa5d2-a438-451b-8eb6-0e913b4200ca@x12g2000yqx.googlegroups.com> <87aasz2mhx.fsf@ludovic-brenta.org> NNTP-Posting-Host: 75.243.4.85 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1271720072 15684 127.0.0.1 (19 Apr 2010 23:34:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 Apr 2010 23:34:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q31g2000prf.googlegroups.com; posting-host=75.243.4.85; posting-account=yOOUcAoAAABjcyl4BUJf9FM0ne56zA9Q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100401 Ubuntu/9.10 (karmic) Firefox/3.5.9,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11054 Date: 2010-04-19T16:34:32-07:00 List-Id: On Apr 19, 1:52=A0pm, Ludovic Brenta wrote: > > I find it funny you should say that because I thought exactly the > opposite: letting Ada.Text_IO (which is notoriously slow) do the > conversion to string and then doing string manipulation is less clear > and more error-prone, IMHO (a proper implementation would use a simple, > but full-fledged, finite state machine). =A0But your approach is certainl= y > valid and correct nevertheless. Funny you should say that ... Considering that I can write function Hex_Image (Number : Ada.Streams.Stream_Element) return String is Result : String (1 .. 10); Start : Natural; package Stream_Element_IO is new Ada.Text_IO.Modular_IO (Num =3D> Ada.Streams.Stream_Element); begin -- Hex_Image Stream_Element_IO.Put (To =3D> Result, Item =3D> Number, Base =3D> 16); Start :=3D Ada.Strings.Fixed.Index (Result, "#") + 1; return Result (Start .. Result'Last - 1); end Hex_Image; and get it right 1st time, compared to the issues you encountered duplicating (some of) the functionality of Put, seems to me evidence that this approach is less error prone. I certainly find it simpler and clearer, too. Getting this to return a zero-filled String of the correct number of digits is slightly more complex: Num_Chars : constant :=3D Ada.Streams.Stream_Element'Size / 4; Result : String (1 .. Num_Chars + 10); ... return String'(1 .. Num_Chars - (Result'Last - Start) =3D> '0') & Result (Start .. Result'Last - 1);