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.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, PDS_FROM_2_EMAILS,STOX_REPLY_TYPE autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f9957894e0bdf128 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe06.iad.POSTED!92f42029!not-for-mail From: "SteveD@teranews.com" Newsgroups: comp.lang.ada References: <407ae64d-3cb3-4310-b59e-f1bbae9910a5@t39g2000prh.googlegroups.com> <71gqm49eatq868htrvd7eghm3m8su8kcbl@4ax.com> <3d3719f4-355c-4094-9902-495d612d46fe@n33g2000pri.googlegroups.com> <139961e9-bae6-4e60-8ff7-4f4779b27481@z6g2000pre.googlegroups.com> <87816592-c947-4bbc-92ed-7473646a105e@a12g2000pro.googlegroups.com> In-Reply-To: Subject: Re: How to put 200 into an integer sub-type of 16 bits (code included) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Thu, 15 Jan 2009 02:39:39 UTC Organization: TeraNews.com Date: Wed, 14 Jan 2009 18:39:35 -0800 Xref: g2news2.google.com comp.lang.ada:4280 Date: 2009-01-14T18:39:35-08:00 List-Id: "ChristopherL" wrote in message news:c265ffb7-6159-4d85-b259-78b830e115f9@v18g2000pro.googlegroups.com... [snip] > >So, what is the proper way to store a number (never being greater than >200.5) in a 8 bit >short number as outlined above? > > >Chris L. I've been watching this thread trying to figure out what it is you're trying to do and I still don't get it. It appears that you are trying to store values in the range of 0 to 200.5 in 8 bits. Are you trying to store a bunch of data values in a small amount of memory? Are you trying to minimize bandwidth for communication? What it comes down to is this: With an 8 bit number you have the ability to distinguish 256 values. If you want to get the best resolution possible for values in the range of 0.0 to 200.5 that you can store in 8 bits, create a linear mapping such that 0.0 maps to 0 and 200.5 maps to 255. 8 bit value = 255.0/200.5 * floatValue To retrieve the value, do the reverse mapping: floatValue = 200.5/255.0 * 8 bit value You probably want to use a lookup table if you're processing a bunch of data. But then again, I'm still unclear on what you're trying to do. Regards, Steve