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.36.66 with SMTP id s2mr7491487qad.6.1367449219599; Wed, 01 May 2013 16:00:19 -0700 (PDT) X-Received: by 10.49.110.167 with SMTP id ib7mr418878qeb.0.1367449219573; Wed, 01 May 2013 16:00:19 -0700 (PDT) Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!l3no1685qak.0!news-out.google.com!ef9ni42111qab.0!nntp.google.com!m7no1596qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 1 May 2013 16:00:19 -0700 (PDT) In-Reply-To: <0b7431ad-fa72-45d4-ac26-20b2c0785d16@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=189.110.14.106; posting-account=TRgI1QoAAABSsYi-ox3Pi6N-JEKKU0cu NNTP-Posting-Host: 189.110.14.106 References: <931385b2-3520-4d7a-b56f-6d0d0b06d467@googlegroups.com> <443a92d3-2327-423d-ad74-174b0a69e4c4@googlegroups.com> <0b7431ad-fa72-45d4-ac26-20b2c0785d16@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <36095985-768d-42f0-a6ab-17eb0e896a4d@googlegroups.com> Subject: Re: AVR Usart send number string with no 'Image From: "Rego, P." Injection-Date: Wed, 01 May 2013 23:00:19 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Original-Bytes: 2484 Xref: number.nntp.dca.giganews.com comp.lang.ada:181337 Date: 2013-05-01T16:00:19-07:00 List-Id: On Wednesday, May 1, 2013 7:32:42 PM UTC-3, Shark8 wrote: > 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; Thanks Shark8, even better than my last one.