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: a07f3367d7,a7135c0f450945a5 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!news.k-dsl.de!news.albasani.net!not-for-mail From: Leslie Newsgroups: comp.lang.ada Subject: Re: How to convert a string containing two hex digits to a character? Date: Tue, 05 Jan 2010 20:42:44 -0600 Organization: albasani.net Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8Bit X-Trace: news.albasani.net hKqJ8yAn9qajKboGH5JShoSwMZCa0e7Z9J9KpAScYHQ5NDXSl8gO4V2WDCRpy2+MnCXgJFFbX+eePTSOVFLFiAc85Nt5dBj+29u20yC0AdB6156leHI18EccttVP0JdB X-Complaints-To: abuse@albasani.net NNTP-Posting-Date: Wed, 6 Jan 2010 02:41:47 +0000 (UTC) X-User-ID: AUZlimKwN37S7/dzvdeOs90dZfdeGVifrtNh6W8DPWeKh9ummCpNTdYw1kehHfbaufvsqmZY8szcLvxjXrBexA== Cancel-Lock: sha1:sAI3rTRHEjzMKbCH1KeIZ1V8PAI= User-Agent: KNode/0.10.9 X-NNTP-Posting-Host: IGa44RsK4Ol3cMZuYL0l62JNMgjX/cZuaCrdBxbaWfk= Xref: g2news1.google.com comp.lang.ada:8629 Date: 2010-01-05T20:42:44-06:00 List-Id: Leslie wrote: > Hibou57 (Yannick Duchêne) wrote: > >> 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 := S'First; >> Low_Order_Digit_Position : constant Positive := >> Positive'Succ >> (High_Order_Digit_Position); >> High_Order_Digit_Representation : constant Character := S >> (High_Order_Digit_Position); >> Low_Order_Digit_Representation : constant Character := 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' => >> Digit_Value := 0 + (Character'Pos (C) - Character'Pos >> ('0')); >> when 'A' .. 'F' => >> Digit_Value := 10 + (Character'Pos (C) - >> Character'Pos >> ('A')); >> when 'a' .. 'f' => >> Digit_Value := 10 + (Character'Pos (C) - >> Character'Pos >> ('a')); >> when others => >> raise Program_Error; >> end case; >> >> Wrap the latter in a function like “ function >> Hexadecimal_Digit_Value (C : Character) return Natural; ” >> >> Then do : >> >> Hexadecimal_Base : constant Natural := 16; >> High_Order_Digit : constant Natural := >> Hexadecimal_Digit_Value >> (High_Order_Digit_Representation); >> Low_Order_Digit : constant Natural := >> Hexadecimal_Digit_Value >> (Low_Order_Digit_Representation); >> Number : constant Natural := (High_Order_Digit * >> Hexadecimal_Base) >> + Low_Order_Digit; > > Okay, wait now; where did Hexadecimal_Digit_Value come > from? It should be declared outside of the function, and is > different than Decimal_Value, is that right? > Gak! Never mind, that's the function call. :-p > Leslie