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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:4e06:: with SMTP id c6mr3089713qtw.360.1589939550600; Tue, 19 May 2020 18:52:30 -0700 (PDT) X-Received: by 2002:aca:dfc5:: with SMTP id w188mr1655828oig.7.1589939550324; Tue, 19 May 2020 18:52:30 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!82.197.223.106.MISMATCH!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 19 May 2020 18:52:30 -0700 (PDT) In-Reply-To: <2c769c87-72f2-4107-b0bf-3846e3ae6c7a@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.17.79; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.17.79 References: <26e971a9-6fcc-4e4c-84ee-d74aecd5b217@googlegroups.com> <2c769c87-72f2-4107-b0bf-3846e3ae6c7a@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <17b4b1bd-89f0-4f7c-80d4-0c1843ac4529@googlegroups.com> Subject: Re: Image attribute (yet again) From: Shark8 Injection-Date: Wed, 20 May 2020 01:52:30 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:58743 Date: 2020-05-19T18:52:30-07:00 List-Id: 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 =C3=A0 00:35, Stephen Davies a =C3=A9crit=C2=A0: > > 'Image is not intending for elaborate formatting, it's a quick debuggin= g > > help. Text_IO has all formatting features for proper IO. Since every > > program has different formatting needs, you have to write you own funct= ion. > >=20 > 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=20 > to String. The method that I typically go with is something like: Subtype Hex_Character is Character with Static_Predicate =3D> Hex_Character in '0'..'9'|'A'..'F'; Type Nybble is range 0..15 with Size =3D> 4; Type Byte is record High, Low : Nybble; end record with Size =3D> 8; -- Rep Clause. Function To_Nybble( Input : Hex_Character ) return Nybble is (case Input is when '0' =3D> 16#0#, when '1' =3D> 16#1#, --... when 'F' =3D> 16#F# ); Function To_Hex_Character( Input : Nybble ) return Hex_Character is (case Input is when 16#0# =3D> '0', when 16#1# =3D> '1', --... when 16#F# =3D> '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 =3D> (for all C of Hex_String =3D> C in Hex_Charac= ter); Function Hex_to_Integer( Input : Hex_String ) return Integer is ( Integer'Image("16#"& Input &'#') );