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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a7135c0f450945a5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,CP1252 Path: g2news1.google.com!postnews.google.com!c34g2000yqn.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Re: How to convert a string containing two hex digits to a character? Date: Tue, 5 Jan 2010 17:22:01 -0800 (PST) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 77.198.58.254 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1262740921 25127 127.0.0.1 (6 Jan 2010 01:22:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 6 Jan 2010 01:22:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c34g2000yqn.googlegroups.com; posting-host=77.198.58.254; posting-account=vrfdLAoAAAAauX_3XwyXEwXCWN3A1l8D User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; fr),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8624 Date: 2010-01-05T17:22:01-08:00 List-Id: You may first convert from two 4 bits digits, that is, convert "7" and "C". 16#7#; -- 7 16#C#; -- 12 To get 16#7C# from 16#7# and 16#C#, just do ((16#7# * 16) + 16#C#) To get 16#7# and 16#C#, first get '7' and 'C' from the string, you may do something like the following (providing your string is named S, and it is an ASCII string) : High_Order_Digit_Position : constant Positive :=3D S'First; Low_Order_Digit_Position : constant Positive :=3D Positive'Succ (High_Order_Digit_Position); High_Order_Digit_Representation : constant Character :=3D S (High_Order_Digit_Position); Low_Order_Digit_Representation : constant Character :=3D S (Low_Order_Digit_Position); To get a digit Natural value from its Character representation, you may do something like the following (providing your character is stored in a Character named C) : case C is when '0' .. '9' =3D> Digit_Value :=3D 0 + (Character'Pos (C) - Character'Pos ('0')); when 'A' .. 'F' =3D> Digit_Value :=3D 10 + (Character'Pos (C) - Character'Pos ('A')); when 'a' .. 'f' =3D> Digit_Value :=3D 10 + (Character'Pos (C) - Character'Pos ('a')); when others =3D> raise Program_Error; end case; Wrap the latter in a function like =93 function Hexadecimal_Digit_Value (C : Character) return Natural; =94 Then do : Hexadecimal_Base : constant Natural :=3D 16; High_Order_Digit : constant Natural :=3D Hexadecimal_Digit_Value (High_Order_Digit_Representation); Low_Order_Digit : constant Natural :=3D Hexadecimal_Digit_Value (Low_Order_Digit_Representation); Number : constant Natural :=3D (High_Order_Digit * Hexadecimal_Base) + Low_Order_Digit;