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!k41g2000yqf.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Hexadecimal and stream element arrays Date: Mon, 19 Apr 2010 09:24:26 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2f4313a5-bb3d-4f7f-8a86-7c8f7d549c53@k41g2000yqf.googlegroups.com> References: NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1271694266 6197 127.0.0.1 (19 Apr 2010 16:24:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 Apr 2010 16:24:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k41g2000yqf.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11034 Date: 2010-04-19T09:24:26-07:00 List-Id: tonyg wrote on comp.lang.ada: > On Apr 19, 4:44=A0pm, tonyg wrote: > > > I have some data coming in from a serial port which I want to convert > > to hexadecimal and display on the screen. I was wondering if anyone > > knows of a simple way to do this? > > To make myself more clear I have already dealt with the serial comms > bit, I am looking to display the stream I have already captured You could use the predefined library to get a result using the Ada "syntax for based literal" (ARM A.10.8(14)), e.g. 16#CE#. package Stream_Element_IO is new Ada.Text_IO.Modular_IO (Num =3D> Ada.Streams.Stream_Element); E : Ada.Streams.Stream_Element :=3D ... begin Stream_Element_IO.Put (Item =3D> E, Base =3D> 16); (There are variants of Put that send the output to a File_Type or to a string). If you want to avoid the 16## part, you can easily convert the stream_elements to a string representation yourself like so: function To_Hex (E : in Ada.Streams.Stream_Element) return String is -- Warning: not compiled and not tested... X : constant array (0 .. 15) of Character :=3D ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); Result : String (1 .. Ada.Streams.Stream_Element'Size / 4); -- 1 hex digits =3D 4 bits Working_Copy : Ada.Streams.Stream_Element :=3D E; use type Ada.Streams.Stream_Element; First_Character : Natural :=3D 0; Base : constant :=3D 16; begin for K in reverse Result'Length loop Result (K) :=3D X (Working_Copy mod Base); Working_Copy :=3D Working_Copy / Base; if Working_Copy =3D 0 then First_Character :=3D K; exit; end if; end loop; return Result (First_Character .. Result'Last); end To_Hex; Hope this helps. -- Ludovic Brenta.