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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13bebe8869a9207e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-07 19:46:55 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: chrissy_brady1@yahoo.com (chrissy) Newsgroups: comp.lang.ada Subject: Re: Octal Conversion in VB Date: 7 Sep 2003 19:46:54 -0700 Organization: http://groups.google.com/ Message-ID: References: <3F5B91AA.4040203@attbi.com> NNTP-Posting-Host: 211.29.166.185 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1062989215 20369 127.0.0.1 (8 Sep 2003 02:46:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Sep 2003 02:46:55 GMT Xref: archiver1.google.com comp.lang.ada:42257 Date: 2003-09-08T02:46:55+00:00 List-Id: "Robert I. Eachus" wrote in message news:<3F5B91AA.4040203@attbi.com>... > 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 actually wanted to produce a string of alphanumerics representing the integer value of a Base 10 integer, converted to Base 8. Thus the ASCII string entered to a text box in VB "94" ultimately returns the string "136". Thanks so much for the suggestion. It's ingenious, but I'm stuck with VB for the moment. Another friend suggested the following for VB: Dim DecimalStr As String Dim OctalStr As String Dim HexadecimalStr As String DecimalStr = InputBox ("Enter decimal value") OctalStr = Oct$(DecimalStr) HexadecimalStr = Hex$(DecimalStr) MsgBox (OctalStr) MsgBox (HexadecimalStr) As a safety mechanism to avoid problems with null values, you could use these lines instead of the corresponding ones above: OctalStr = Oct$(DecimalStr & " ") HexadecimalStr = Hex$(DecimalStr & " ") This of course does much more than I'd asked, as it's handling hexadecimals as well. The same friend also offered me a solution in Pascal: I've attached a generic base conversion program in Pascal for bases from 2 to 36 but there's no error handling. These are fairly standard algorithms. The programing term is 'cliches'. It converts from any base to any base. Louie. ----------------------------------------------------------------------------- Tabs set to 4 spaces { baseconvert.pas - Base convertor of integers Luis Esteban 8 September 2003 Created without error checking } program BaseConvertor (input, output); var InputNumber : string; OutputNumber : string; InputBase : integer; OutputBase : integer; Value : longint; function StringToInteger (Number : string; Base : integer) : longint; var Accumulator : longint; i : integer; begin Accumulator := 0; for i := 1 to Length(Number) do begin {writeln ('Number[', i:1, '] = ', Number[i]);} if Number[i] in ['0'..'9'] then begin Accumulator := Accumulator * Base + (ord(Number[i]) - ord('0')); end else if Number[i] in ['A'..'Z'] then begin Accumulator := Accumulator * Base + (10 + ord(Number[i]) - ord('A')); end else if Number[i] in ['a'..'z'] then begin Accumulator := Accumulator * Base + (10 + ord(Number[i]) - ord('a')); end else begin writeln ('Ignoring ''', Number[i], ''''); end; end; StringToInteger := Accumulator; end; function ReverseString (s : string) : string; var i : integer; t : string; begin t := ''; for i := Length(s) downto 1 do begin t := t + s[i]; end; ReverseString := t; end; function IntegerToString (Number : longint; Base : integer) : string; var r : string; NewDigit : integer; begin r := ''; while Number > 0 do begin NewDigit := Number mod Base; if NewDigit < 10 then begin r := r + chr(NewDigit+ord('0')); end else if NewDigit < 36 then begin r := r + chr(NewDigit+ord('A')-10); end; Number := Number div Base; end; IntegerToString := ReverseString (r); end; begin write ('Enter number: '); readln (InputNumber); write ('Enter input base: '); readln (InputBase); write ('Enter output base: '); readln (OutputBase); writeln; Value := StringToInteger(InputNumber, InputBase); OutputNumber := IntegerToString(Value, OutputBase); writeln (InputNumber,'(',InputBase,') = ',Value,'(10) = ',OutputNumber,'(',OutputBase,')'); end. Again this is more than I'd asked for. I'm so impressed with the software community. You guys are just so generous!! With Lots of Thanks and other Sincere signals of fratitude Chrissy