comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Hexadecimal and stream element arrays
Date: Mon, 19 Apr 2010 19:27:00 +0200
Date: 2010-04-19T19:26:59+02:00	[thread overview]
Message-ID: <13872qpzb35yu$.9mbqdk8efq0p.dlg@40tude.net> (raw)
In-Reply-To: f7e8f2a4-a989-4b74-b66e-b248d684d5ae@z11g2000yqz.googlegroups.com

On Mon, 19 Apr 2010 08:58:16 -0700 (PDT), tonyg wrote:

> On Apr 19, 4:44�pm, tonyg <tonytheg...@googlemail.com> 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:

   http://www.dmitry-kazakov.de/ada/strings_edit.htm

with Ada.Streams;            use Ada.Streams;
with Strings_Edit;           use Strings_Edit;
with Strings_Edit.Integers;  use Strings_Edit.Integers;

function Image (Data : Stream_Element_Array) return String is
begin
   if Data'Length = 0 then
      return "";
   end if;
   declare
      Text    : String (1..Data'Length * 3);
      Pointer : Integer := 1;
   begin
      for I in Data'Range loop
         Put
         (  Text, Pointer, Stream_Element'Pos (Data (I)),
            Field=>2, Fill=>'0', Justify=>Right, Base=>16
         );
         Put (Text, Pointer, ' ');
      end loop;
      return Text (1..Text'Last - 1);
   end;
end Image;

An individual item is output

   Put
   (  Text, Pointer, Stream_Element'Pos (Item),
       Field=>2, Fill=>'0', Justify=>Right, Base=>16
   );

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2010-04-19 17:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-19 15:44 Hexadecimal and stream element arrays tonyg
2010-04-19 15:58 ` tonyg
2010-04-19 16:24   ` Ludovic Brenta
2010-04-19 16:27     ` tonyg
2010-04-19 17:02       ` tonyg
2010-04-19 17:26         ` tonyg
2010-04-19 20:50           ` Ludovic Brenta
2010-04-20  9:00             ` tonyg
2010-04-20  9:25               ` Peter Hermann
2010-04-19 18:05     ` Warren
2010-04-19 19:21       ` Jeffrey R. Carter
2010-04-19 19:28         ` Warren
2010-04-19 23:21           ` John B. Matthews
2010-04-19 23:22           ` Adam Beneschan
2010-04-20 14:04             ` Warren
2010-04-20 14:46               ` J-P. Rosen
2010-04-20 15:52                 ` Warren
2010-04-19 19:17     ` Jeffrey R. Carter
2010-04-19 20:52       ` Ludovic Brenta
2010-04-19 23:34         ` Jeffrey R. Carter
2010-04-19 17:20   ` John B. Matthews
2010-04-19 17:27   ` Dmitry A. Kazakov [this message]
2010-04-19 17:55     ` tonyg
2010-04-20  7:25 ` Stephen Leake
2010-04-20 22:21   ` Jeffrey R. Carter
2010-04-21 12:38     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox