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-7-bit Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Hexadecimal and stream element arrays References: Date: Tue, 20 Apr 2010 03:25:41 -0400 Message-ID: <82fx2q4mbu.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (windows-nt) Cancel-Lock: sha1:gEPbWd+hBM7FvRycjGjtU/s14KM= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 627674bcd5737e197caa713121 Xref: g2news1.google.com comp.lang.ada:10085 Date: 2010-04-20T03:25:41-04:00 List-Id: tonyg 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