From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Image attribute (yet again)
Date: Tue, 19 May 2020 18:52:30 -0700 (PDT)
Date: 2020-05-19T18:52:30-07:00 [thread overview]
Message-ID: <17b4b1bd-89f0-4f7c-80d4-0c1843ac4529@googlegroups.com> (raw)
In-Reply-To: <2c769c87-72f2-4107-b0bf-3846e3ae6c7a@googlegroups.com>
On Sunday, April 26, 2020 at 8:16:46 AM UTC-6, Jere wrote:
> On Sunday, April 26, 2020 at 2:05:59 AM UTC-4, J-P. Rosen wrote:
> > Le 26/04/2020 à 00:35, Stephen Davies a écrit :
> > 'Image is not intending for elaborate formatting, it's a quick debugging
> > help. Text_IO has all formatting features for proper IO. Since every
> > program has different formatting needs, you have to write you own function.
> >
> This might be a good time to ask since this comes up all the time
> for me, but where are the formatting options for hexadecimal
> to String.
The method that I typically go with is something like:
Subtype Hex_Character is Character
with Static_Predicate => Hex_Character in '0'..'9'|'A'..'F';
Type Nybble is range 0..15 with Size => 4;
Type Byte is record
High, Low : Nybble;
end record with Size => 8;
-- Rep Clause.
Function To_Nybble( Input : Hex_Character ) return Nybble is
(case Input is
when '0' => 16#0#,
when '1' => 16#1#,
--...
when 'F' => 16#F#
);
Function To_Hex_Character( Input : Nybble ) return Hex_Character is
(case Input is
when 16#0# => '0',
when 16#1# => '1',
--...
when 16#F# => 'F'
);
Function Byte_to_Hex( Input : Byte ) return String is
( HexChar( Input.High ) & HexChar( Input.High ) );
Though for one application I made a proper Hex_Character character-type and used the 'pos/'val/'image/'value attributes.
You can also get easy string conversions with 'Value, especially:
Subtype Hex_String is String
with Dynamic_Predicate => (for all C of Hex_String => C in Hex_Character);
Function Hex_to_Integer( Input : Hex_String ) return Integer is
( Integer'Image("16#"& Input &'#') );
next prev parent reply other threads:[~2020-05-20 1:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 15:24 Image attribute (yet again) Stephen Davies
2020-04-25 22:35 ` Stephen Davies
2020-04-26 6:05 ` J-P. Rosen
2020-04-26 14:16 ` Jere
2020-04-26 17:09 ` Jeffrey R. Carter
2020-04-26 17:33 ` Jere
2020-04-27 12:33 ` J-P. Rosen
2020-04-27 12:50 ` Jere
2020-04-27 13:42 ` J-P. Rosen
2020-04-27 14:05 ` Jere
2020-04-27 14:55 ` Jeffrey R. Carter
2020-04-28 6:04 ` J-P. Rosen
2020-04-27 14:10 ` Jere
2020-04-28 6:02 ` J-P. Rosen
2020-04-28 13:03 ` Jere
2020-04-26 18:40 ` Oliver Kellogg
2020-04-26 18:42 ` Oliver Kellogg
2020-04-26 18:43 ` Oliver Kellogg
2020-04-27 12:52 ` Jere
2020-05-20 1:52 ` Shark8 [this message]
2020-04-26 18:57 ` Stephen Davies
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox