From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Hexadecimal and stream element arrays
Date: Tue, 20 Apr 2010 03:25:41 -0400
Date: 2010-04-20T03:25:41-04:00 [thread overview]
Message-ID: <82fx2q4mbu.fsf@stephe-leake.org> (raw)
In-Reply-To: c75b8be4-f412-4fc9-b4e7-d9a8ac22ea4f@k36g2000yqb.googlegroups.com
tonyg <tonythegair@googlemail.com> writes:
> 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?
Just to chime in with my generic solution to this (from SAL
http://www.stephe-leake.org/ada/sal.html) :
pragma License (Modified_GPL);
generic
Width : Natural;
type Number_Type is mod <>;
function SAL.Generic_Hex_Image (Item : in Number_Type) return String;
-- Return a hexadecimal image of Item, padded with leading zeros to
-- Width. If Width is too small for Item, leading digits are silently
-- truncated.
pragma Pure (SAL.Generic_Hex_Image);
function SAL.Generic_Hex_Image (Item : in Number_Type) return String
is
Temp : Number_Type := Item;
Nibble : Number_Type;
Image : String (1 .. Width);
begin
for I in reverse Image'Range loop
Nibble := Temp mod 16;
Temp := Temp / 16;
if Nibble > 9 then
Image (I) := Character'Val (Character'Pos ('A') + Integer (Nibble) - 10);
else
Image (I) := Character'Val (Character'Pos ('0') + Integer (Nibble));
end if;
end loop;
return Image;
end SAL.Generic_Hex_Image;
--
-- Stephe
next prev parent reply other threads:[~2010-04-20 7:25 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
2010-04-19 17:55 ` tonyg
2010-04-20 7:25 ` Stephen Leake [this message]
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