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,6171b9ea6dd53ab,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k70g2000cwa.googlegroups.com!not-for-mail From: "laehyung" Newsgroups: comp.lang.ada Subject: Advice Please Date: 9 Nov 2006 22:52:15 -0800 Organization: http://groups.google.com Message-ID: <1163141535.700889.83160@k70g2000cwa.googlegroups.com> NNTP-Posting-Host: 210.94.44.1 Mime-Version: 1.0 Content-Type: text/plain; charset="euc-kr" X-Trace: posting.google.com 1163141540 7300 127.0.0.1 (10 Nov 2006 06:52:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Nov 2006 06:52:20 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k70g2000cwa.googlegroups.com; posting-host=210.94.44.1; posting-account=U7xvTA0AAAAT2rJ0AMIsYEWaGxye33J6 Xref: g2news2.google.com comp.lang.ada:7394 Date: 2006-11-09T22:52:15-08:00 List-Id: Advice & comments please. my test code is ... with Ada.Text_IO; use Ada.Text_IO; with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Unchecked_Conversion; with Interfaces; use Interfaces; with Interfaces.C; procedure Test_Str is --------------------------------------- function Conv_U8_To_Char is new Ada.Unchecked_Conversion(Source => Unsigned_8, Target => Character); function Conv_Char_To_U8 is new Ada.Unchecked_Conversion(Source => Character, Target => Unsigned_8); --------------------------------------- function Strhex_To_Ascii_Strbyte (Item : in String) return String is Strsize : Natural := Item'Length; Rtn_Length : Natural := (Strsize)/2; Str_Val : String(1..Rtn_Length); Strtemp1 : Unsigned_8; Strtemp2 : Unsigned_8; C : array(1..Strsize) of Unsigned_8; begin for Idx in Item'range loop if Is_Hexadecimal_Digit(Item(Idx)) then if Is_Digit(Item(Idx)) then C(Idx):= Unsigned_8(Character'Pos(Item(Idx))-Character'Pos('0')); else C(Idx):= Unsigned_8(Character'Pos(To_Upper(Item(Idx))) -Character'Pos('A')+16#A#); end if; else Put_Line("Program Code contains NON-HexaDecimal character. program Break"); raise Data_Error; end if; end loop; for I in 1..Rtn_Length loop Strtemp1 := Shift_Left(Unsigned_8(C(2*I-1)),4) and Unsigned_8(16#FF#); Strtemp2 := Unsigned_8(C(2*I)) and Unsigned_8(16#FF#); Str_Val(I) := Conv_U8_To_Char( Strtemp1 or Strtemp2 ); end loop; return Str_Val; end Strhex_To_Ascii_Strbyte; --------------------------------------- Input_Str : String := "0000002D0F010000002E0F000000000A10A3"; begin --Put("Output_Str =>"); Put(Strhex_To_Ascii_Strbyte(Input_Str)); end Test_Str; ---------------------------------------------------------------- (my machine is windows XP) Compile & Run: c:\work>gnatmke -O2 -gnatvf test_str gcc -c -O2 -gnatvf test_str.adb GNAT GPL 2006 (20060522-34) Copyright 1992-2006, Free Software Foundation, Inc. Compiling: test_str.adb (source file time stamp: 2006-11-10 05:22:28) 68 lines: No errors gnatbind -x test_str.ali gnatlink test_str.ali c:\work> test_str > code_test.txt edit code_test.txt file with hexa code editor(ex. UltraEdit-32) output data shold be 00000000h:00 00 00 2D 0F 01 00 00 00 2E 0F 00 00 00 00 00 ;...-............ 00000010h:0A 10 A3 0D 0A ;..?. but result is 00000000h:00 00 00 2D 0F 01 00 00 00 2E 0F 00 00 00 00 0D ;...-............ 00000010h:0A 10 A3 0D 0A ;..?. the data of address 0Fh is 0D, why? How to correct this problem.