This bounced for some reason so I'm sending it again. Apologies if it shows up twice for some reason. -----Original Message----- From: Al Williams To: Randie Ohtsji [4555] Cc: PICLIST@MITVMA.MIT.EDU Date: Tuesday, March 10, 1998 8:40 AM Subject: Re: degrees C to degrees F conversion >You don't mention how accurate or what range you need to cover. However, >here's something you might find useful: > >1) Store everything to the 1/10 of 1 degree (in other words 100 deg --> >1000) >2) Display only to 1 degree (chop off last digit on output) >3) Round up (if that last digit is 5 or more, add 1 to the second to last >digit and propagate any carry). >4) Use 32 bit math > >Now, given that: > >F=(64C+32C+16C+2C+C)/64+320 >Ctmp=F-320 >C=(128Ctmp+8Ctmp+4Ctmp+2Ctmp)/256 > >Suppose you start with 100 deg. C: >You really store that as 1000 so: >(64(1000)+32(1000)+16(1000)+2(1000)+1000)/64+320=2116 (211.6, rounds up to >212) > >Or, start with 212 deg F: >This is 2120 so Ctmp is 1800 >Then: >(128(1800)+8(1800)+4(1800)+2(1800))/256 = 998 (99.8, rounds up to 100) > >Of course, all of these multiplies and divides can be done using shifts. >Shift left once for *2, twice for *4, thrice for *8, etc. Shift right once >for /2, twice for /4, etc. > >Then the only hard part is to convert to decimal which there are many >routines for that (mostly requiring /10). However, if you are data logging >(DAU), you may be able to push that processing to the PC (or other DMU). If >you are doing math, the error may not be significant, and you can just >rewrite your equations so they all expect 10C or 10F instead of C or F. > >Does this make any sense? I'm still jet lagged, so who knows. Anyway, if I >didn't make it plain, ask me again and maybe I'll be clearer later :-) > >Regards, > >Al Williams >AWC >*Solderless Stamp and PIC Prototypes at http://www.al-williams.com/awce.htm >--->Pick up your FREE Basic Stamp I Simulator for Windows at the same >address. > > >-----Original Message----- >From: Randie Ohtsji [4555] >Date: Monday, March 09, 1998 12:56 PM >Subject: degrees C to degrees F conversion > > >>Hello, >> >>Does anyone have a simple way of converting from degrees Celsius >>to degrees Fahrenheit (and vice-versa) using PIC math? >> >>C -> F >>====== >>C*9/5 + 32 >> >> >>F -> C >>====== >>(F-32)(5/9) >> >> >>Thanks in advance! >> >>-Randie >>rohtsji@glenayre.com >> >