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,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13bebe8869a9207e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-07 13:14:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail Message-ID: <3F5B91AA.4040203@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Octal Conversion in VB References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc03 1062965690 24.34.139.183 (Sun, 07 Sep 2003 20:14:50 GMT) NNTP-Posting-Date: Sun, 07 Sep 2003 20:14:50 GMT Organization: Comcast Online Date: Sun, 07 Sep 2003 20:14:50 GMT Xref: archiver1.google.com comp.lang.ada:42244 Date: 2003-09-07T20:14:50+00:00 List-Id: Ludovic Brenta wrote: > Here is a general algorithm that does what you want. Note that you > need some mathematical background to understand why there are > log(N)/log(8) octal digits in any integer number. I think chrissy was actually looking to convert (ASCII?) characters into octal triplets. Something more like what follows. (I almost feel I should apolgize for all the formatting and usage code, because it tends to obscure what is going on. On the other hand, the conversion to octal not hex or decimal is chosen by the number in the line with the 8 is base comment. (Actually for decimal I'd omit the ten and change the dimensions of Temp, but that is a detail. ;-) with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Command_Line; use Ada.Command_Line; procedure Octal is -- a program to convert text strings into octal. Temp: String(1..6); begin if Argument_Count /= 1 then Put_Line(" Usage: octal ""string"""); Put_Line(" If the string does not contain blanks or other special command line"); Put_Line(" characters, the parentheses may be omitted."); Set_Exit_Status(Failure); return; end if; for I in Argument(1)'Range loop if Col >= 80 then New_Line; end if; Put(Temp,Character'Pos(Argument(1)(I)),8); -- 8 is base pragma Debug(Put_Line('"' & Temp & '"')); if Temp(2) = ' ' then Temp(3..4) := "00"; elsif Temp(1) = ' ' then Temp(3) := '0'; end if; -- change leading blanks to zeros Put(' '); Put(Temp(3..5)); end loop; end Octal; with output: E:\Ada\Test>octal "This is a very long string..." octal "This is a very long string..." 124 150 151 163 040 151 163 040 141 040 166 145 162 171 040 154 157 156 147 040 163 164 162 151 156 147 056 056 056 E:\Ada\Test>octal foobar octal foobar 146 157 157 142 141 162 E:\Ada\Test>octal octal Usage: octal "string" If the string does not contain blanks or other special command line characters, the parentheses may be omitted. -- Robert I. Eachus "As far as I'm concerned, war always means failure." -- Jacques Chirac, President of France "As far as France is concerned, you're right." -- Rush Limbaugh