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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e1bb40a3d604c4b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 11 Jun 2010 07:25:58 -0500 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: What is the best way to convert Integer to Short_Short_Integer? Date: Fri, 11 Jun 2010 13:31:55 +0100 Reply-To: brian@shapes.demon.co.uk Message-ID: References: X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-AEdZBTipzqFirui5uFmjQPmSUYja4Wi4nMn8S8mMyGPOXD//QyTeSI2n0UmamlXN6QqnMosGsQz5U61!PVRLvrBijXh0aR8Jobc2hodnitlm9z7qoWP7OKC8DDqeOXwx0hc53R1sS1p0yP0DKo/cUTXTqntH!Q7P5 X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Xref: g2news2.google.com comp.lang.ada:12615 Date: 2010-06-11T13:31:55+01:00 List-Id: On Fri, 11 Jun 2010 00:07:16 -0700, "Jeffrey R. Carter" wrote: >Adrian Hoe wrote: >> >> I have a number which is in the range of -128..127 and is read as >> Integer (32-bit). >>... we can use either method: type conversion >> as Jeff suggested or use Unchecked_Conversion. > >Which byte of the 32-bit integer will Unchecked_Conversion return? Good question. On which machine? :-) >> Which is the preferred method? Short_Short_Integer (I) or >> Unchecked_Conversion? > >A type conversion is preferred. And it has no downside. If you need to distinguish between errors here and a more general "constraint error", it is easy to wrap the conversion in a function which locally handles "constraint error", and does something appropriate (e.g. saturates, or raises "range error"). - Brian