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,FREEMAIL_FROM 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!u34g2000yqu.googlegroups.com!not-for-mail From: tonyg Newsgroups: comp.lang.ada Subject: Re: Hexadecimal and stream element arrays Date: Mon, 19 Apr 2010 10:55:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <13872qpzb35yu$.9mbqdk8efq0p.dlg@40tude.net> NNTP-Posting-Host: 92.233.204.67 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1271699756 5210 127.0.0.1 (19 Apr 2010 17:55:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 19 Apr 2010 17:55:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u34g2000yqu.googlegroups.com; posting-host=92.233.204.67; posting-account=28F2IwkAAACL1Z5nRC-dE7zuvWdbWC7P User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.1.9) Gecko/20100402 Ubuntu/9.10 (karmic) Firefox/3.5.9,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11040 Date: 2010-04-19T10:55:56-07:00 List-Id: On Apr 19, 6:27=A0pm, "Dmitry A. Kazakov" wrote: > On Mon, 19 Apr 2010 08:58:16 -0700 (PDT), tonyg wrote: > > On Apr 19, 4:44 pm, 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 > > The following is based on: > > =A0 =A0http://www.dmitry-kazakov.de/ada/strings_edit.htm > > with Ada.Streams; =A0 =A0 =A0 =A0 =A0 =A0use Ada.Streams; > with Strings_Edit; =A0 =A0 =A0 =A0 =A0 use Strings_Edit; > with Strings_Edit.Integers; =A0use Strings_Edit.Integers; > > function Image (Data : Stream_Element_Array) return String is > begin > =A0 =A0if Data'Length =3D 0 then > =A0 =A0 =A0 return ""; > =A0 =A0end if; > =A0 =A0declare > =A0 =A0 =A0 Text =A0 =A0: String (1..Data'Length * 3); > =A0 =A0 =A0 Pointer : Integer :=3D 1; > =A0 =A0begin > =A0 =A0 =A0 for I in Data'Range loop > =A0 =A0 =A0 =A0 =A0Put > =A0 =A0 =A0 =A0 =A0( =A0Text, Pointer, Stream_Element'Pos (Data (I)), > =A0 =A0 =A0 =A0 =A0 =A0 Field=3D>2, Fill=3D>'0', Justify=3D>Right, Base= =3D>16 > =A0 =A0 =A0 =A0 =A0); > =A0 =A0 =A0 =A0 =A0Put (Text, Pointer, ' '); > =A0 =A0 =A0 end loop; > =A0 =A0 =A0 return Text (1..Text'Last - 1); > =A0 =A0end; > end Image; > > An individual item is output > > =A0 =A0Put > =A0 =A0( =A0Text, Pointer, Stream_Element'Pos (Item), > =A0 =A0 =A0 =A0Field=3D>2, Fill=3D>'0', Justify=3D>Right, Base=3D>16 > =A0 =A0); > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Thanks Guys, I forgot how helpful these forums were and how many people out there used Ada, you reminded me, and I got some working code \o/