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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.217.195 with SMTP id hn3mr7384557qab.5.1367447563140; Wed, 01 May 2013 15:32:43 -0700 (PDT) X-Received: by 10.50.1.2 with SMTP id 2mr3051036igi.6.1367447562981; Wed, 01 May 2013 15:32:42 -0700 (PDT) Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!209.197.12.246.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!s14no1772452qam.0!news-out.google.com!ef9ni41903qab.0!nntp.google.com!s14no1803581qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 1 May 2013 15:32:42 -0700 (PDT) In-Reply-To: <443a92d3-2327-423d-ad74-174b0a69e4c4@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: <931385b2-3520-4d7a-b56f-6d0d0b06d467@googlegroups.com> <443a92d3-2327-423d-ad74-174b0a69e4c4@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0b7431ad-fa72-45d4-ac26-20b2c0785d16@googlegroups.com> Subject: Re: AVR Usart send number string with no 'Image From: Shark8 Injection-Date: Wed, 01 May 2013 22:32:43 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 2419 X-Original-Bytes: 2704 Xref: number.nntp.dca.giganews.com comp.lang.ada:181335 Date: 2013-05-01T15:32:42-07:00 List-Id: On Wednesday, May 1, 2013 2:35:02 PM UTC-6, Rego, P. wrote: > Now I am trying to implement the inverse (String to Unsigned_8), > But the result is not right. Maybe did I forget something? declare Use Interfaces; Subtype Digit is Character Range '0'..'9'; Subtype String3 is String(1..3); Function From_String(Input : String3) return Unsigned_8 is Working : String3 := Input; Index : Unsigned_8 := 1; begin -- preprocessing string: spaces are treated as 0. for C of Working loop C := (if C = ' ' then '0' else C); -- throw error if invalid characters exist. if C not in Digit then raise Numeric_Error; end if; -- Note a case statement might habe been -- nore appropriate for this block. end loop; Return Result : Unsigned_8 := 0 do for C of reverse Working loop -- We add the current character's value, multiplied -- by its position, to modify result. Result:= Result + Index * (Character'Pos(C) - Character'Pos('0')); -- The following works because wrap-around isn't an error. -- If we weren't using Unsigned_8 we would need a cast. Index:= Index * 10; end loop; End return; End From_String;