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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,49ddd117f54c2d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: mike.martelli@gmail.com Newsgroups: comp.lang.ada Subject: Re: New to Ada, noticing something strange. Date: 29 Sep 2005 16:58:33 -0700 Organization: http://groups.google.com Message-ID: <1128038313.717692.268490@z14g2000cwz.googlegroups.com> References: <1128014442.343461.185800@g49g2000cwa.googlegroups.com> <_xW_e.4596$zQ3.2632@newsread1.news.pas.earthlink.net> <1128020747.226853.325750@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 67.80.105.56 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1128038319 5592 127.0.0.1 (29 Sep 2005 23:58:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 29 Sep 2005 23:58:39 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=67.80.105.56; posting-account=2Kx9Xw0AAADNctxkDMILsC-KEZIDvZ3h Xref: g2news1.google.com comp.lang.ada:5289 Date: 2005-09-29T16:58:33-07:00 List-Id: Ok, Randy sounds good here is my code. I also tried compiling in on Laptop with the latest GNAT compilier and I get the same results. ================================================== with Ada.Text_IO; with Ada.Integer_Text_IO; with Ada.Command_Line; with Ada.Strings.Unbounded; with Ada.Characters.Handling; use Ada.Text_IO; use Ada.Integer_Text_IO; use Ada.Command_Line; use Ada.Strings.Unbounded; procedure BigInts is base, operand1, operand2: Unbounded_String := To_Unbounded_String(""); charMap: array (Character) of Integer; NumOfArgs, size, carry: Integer := 0; charBase, digit, charDigit: Character; procedure PopulateArray is begin charMap('0') := 0; charMap('1') := 1; charMap('2') := 2; charMap('3') := 3; charMap('4') := 4; charMap('5') := 5; charMap('6') := 6; charMap('7') := 7; charMap('8') := 8; charMap('9') := 9; charMap('A') := 10; charMap('B') := 11; charMap('C') := 12; charMap('D') := 13; charMap('E') := 14; charMap('F') := 15; end PopulateArray; function ResultSize(operand1, operand2: Unbounded_String) return Integer is begin if Length(operand1) > Length(operand2) then size := Length(operand1); else size := Length(operand2); end if; return size; end ResultSize; function Convert2Character(strChar: String) return Character is begin --Put_Line(strChar); case Integer'Value(strChar) is when 10 => return 'A'; when 11 => return 'B'; when 12 => return 'C'; when 13 => return 'D'; when 14 => return 'E'; when 15 => return 'F'; when others => return strChar(1); end case; end Convert2Character; function AddDigits(charOp1, charOp2: Character) return Character is begin charDigit := Convert2Character(Integer'Image(charMap(charOp1) + charMap(charOp2) + carry)); Put("Print1: "); Put(Convert2Character(Integer'Image(charMap(charOp1) + charMap(charOp2) + carry))); if (charMap(charOp1) + charMap(charOp2) + carry) > (charMap(charBase) - 1) then Put_Line("here1: "); charDigit := Convert2Character(Integer'Image(charMap(charBase) - 1)); --Set the digit to the highest possible values carry := (charMap(charOp1) + charMap(charOp2) + carry) - (charMap(charBase) - 1); --carry is all of the rest else Put_Line("here2: "); carry := 0; --there is no carry end if; Put("Digit: "); Put(charDigit); New_Line; Put("Carry: "); Put(carry); New_Line; return charDigit; end AddDigits; begin NumOfArgs := ARGUMENT_COUNT; if NumOfArgs = 3 then base := To_Unbounded_String(Argument(1)); operand1 := To_Unbounded_String(Argument(2)); operand2 := To_Unbounded_String(Argument(3)); if not (Integer'Value(To_String(base)) > 1) or not (Integer'Value(To_String(base)) < 16) then Put("The base entered is not valid."); return; end if; charBase := Convert2Character(To_String(base)); --converts all lowercase characters to uppercase for i in 1 .. Length(operand1) loop case Element(operand1, i) is when 'a' => Replace_Element(operand1, i, 'A'); when 'b' => Replace_Element(operand1, i, 'B'); when 'c' => Replace_Element(operand1, i, 'C'); when 'd' => Replace_Element(operand1, i, 'D'); when 'e' => Replace_Element(operand1, i, 'E'); when 'f' => Replace_Element(operand1, i, 'F'); when others => Replace_Element(operand1, i, Element(operand1, i)); end case; end loop; --converts all lowercase characters to uppercase for i in 1 .. Length(operand2) loop case Element(operand2, i) is when 'a' => Replace_Element(operand2, i, 'A'); when 'b' => Replace_Element(operand2, i, 'B'); when 'c' => Replace_Element(operand2, i, 'C'); when 'd' => Replace_Element(operand2, i, 'D'); when 'e' => Replace_Element(operand2, i, 'E'); when 'f' => Replace_Element(operand2, i, 'F'); when others => Replace_Element(operand2, i, Element(operand2, i)); end case; end loop; PopulateArray; for i in 1 .. Length(operand1) loop if charMap(To_String(operand1)(i)) >= charMap(charBase) then Put_Line("Operand 1 is not valid with the base entered"); return; end if; end loop; for i in 1 .. Length(operand2) loop if charMap(To_String(operand2)(i)) >= charMap(charBase) then Put_Line("Operand 2 is not valid with the base entered"); return; end if; end loop; for i in reverse 1 .. ResultSize(operand1,operand2) loop digit := AddDigits(To_String(operand1)(i), To_String(operand2)(i)); Put(digit); New_Line; end loop; --Print final carry digit Put("Final Carry: "); Put(carry); New_Line; else Put("Not enough args"); return; end if; end BigInts;