<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Multiplication Help Wanted!!</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/36750/multiplication-help-wanted</link><description> Dear Keil Community, 
 
I have built a digital thermomter using AT89C52. I have to display the temp on a LCD. The ADC is 10 bits and after coversion routines, i get the hex equivalent of temperature as 368. Now 368 is to be diplayed as 3.406 on LCD.</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Multiplication Help Wanted!!</title><link>https://community.arm.com/thread/87222?ContentTypeID=1</link><pubDate>Mon, 23 May 2005 08:29:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:deeff763-f84b-49c6-bcf5-2037f7050f09</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;i&gt;Let me show you the somewhat crude fixed-point alternative:&lt;/i&gt;&lt;br /&gt;
Hans-Bernhard, did you forget&lt;br /&gt;
&lt;br /&gt;
the &lt;b&gt;much faster&lt;/b&gt;fixed-point alternative&lt;br /&gt;
&lt;br /&gt;
Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiplication Help Wanted!!</title><link>https://community.arm.com/thread/44056?ContentTypeID=1</link><pubDate>Mon, 23 May 2005 03:55:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fe084844-a779-45c4-bbfd-2767a537e058</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;You&amp;#39;ve been shown the straight-forward floating-point method.  Let me show you the somewhat crude fixed-point alternative:&lt;br /&gt;
&lt;pre&gt;fraction = ((unsigned long) (dac_val &amp;amp; 0xff)) * 1000 + 128) / 256&lt;/pre&gt;
&lt;br /&gt;
For a dac_val of 0x368, this gives decimal 406, i.e. exactly the fractional part of the number you want to print.&lt;br /&gt;
&lt;br /&gt;
The trick is to multiply *first*, before you&lt;br /&gt;
divide by 256, and to add the offset of 0.5 in the last digit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiplication Help Wanted!!</title><link>https://community.arm.com/thread/87221?ContentTypeID=1</link><pubDate>Sun, 22 May 2005 17:57:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7b272731-854e-42ed-a6fd-be83dd512405</guid><dc:creator>Karl Hamsher</dc:creator><description>&lt;p&gt;&lt;i&gt;&lt;pre&gt;unsigned short rawTemp; /* 10bit ADC value */
float actualTemp;

actualTemp = (rawTemp &amp;amp; 0xf00) &amp;gt;&amp;gt; 8; /* scale the units */
actualTemp += ((rawTemp &amp;amp; 0xf0) &amp;gt;&amp;gt; 4)/16 /* scale the 1/16&amp;#39;s */
actualTemp += (rawTemp &amp;amp; 0x0f)/256; /* scale the 1/256&amp;#39;s */&lt;/pre&gt;&lt;/i&gt;&lt;br /&gt;
Or simply:&lt;br /&gt;
&lt;pre&gt;unsigned short rawTemp; /* 10bit ADC value */
float actualTemp;

actualTemp = rawTemp / 256.0;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiplication Help Wanted!!</title><link>https://community.arm.com/thread/44058?ContentTypeID=1</link><pubDate>Sun, 22 May 2005 17:28:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2fcb4008-736e-4adb-a8c3-79a5768c2e54</guid><dc:creator>Mark H</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;
&lt;br /&gt;
Why not do exactly as you have described the problem? by creating a float variable to store the result.&lt;br /&gt;
&lt;br /&gt;
Say something like:-&lt;br /&gt;
&lt;pre&gt;
unsigned short rawTemp; /* 10bit ADC value */
float actualTemp;

actualTemp = (rawTemp &amp;amp; 0xf00) &amp;gt;&amp;gt; 8; /* scale the units */
actualTemp += ((rawTemp &amp;amp; 0xf0) &amp;gt;&amp;gt; 4)/16 /* scale the 1/16&amp;#39;s */
actualTemp += (rawTemp &amp;amp; 0x0f)/256; /* scale the 1/256&amp;#39;s */
&lt;/pre&gt;
&lt;br /&gt;
Note you may for have to cast rawTemp to a float before doing the divides and now possibly &amp;#39;sprintf&amp;#39; the value to a string ready to format for lcd display.&lt;br /&gt;
&lt;br /&gt;
Hope this helps,&lt;br /&gt;
Mark.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>