Searching \ for 'Programming Challenge - Celsius to Fahrenheit BCD' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Programming Challenge - Celsius to Fahrenheit BCD'.

Truncated match.
PICList Thread
'Programming Challenge - Celsius to Fahrenheit BCD'
1997\09\26@201549 by Alan G. Smith

It is commonly known that
  tempF = (9/5)tempC + 32

While helping a friend of mine working with a DS1620, I showed him that
9/5tempC is equal to:
(tempC << 1) - (tempC >> 2) + (tempC >> 4) - (tempC >> 6) +..........

I came up with a real short, quick routine to do this if tempC is between 0 and
And that started me thinking......
Hmmmm....  How to do it fast if it was negative, and since he really wants it in
BCD why convert it
to decimal first.

So here is my challenge:
Your routine is called with a flag called CelsNeg set if the temperature is
negative (and clear if
it is positive.)
You can access it as
bsf flags, CelsNeg.
The absolute of the temperature is stored in 1/2 step increments is stored in a
variable called
(e.g. 0x02 = 1C, 0x32 = 25C)
You must store whether the Fahrenheit is negative or not in a flag called
FahrenNeg (also in the
flags variable.)
Then you must store the value of the Fahrenheit temperature in BCD in one var.
If the Fahrenheit temperature won't fit in two digits then you need to set the
ConvertError flag.
Celsius temperature will range from -55 to 125.

Points are scored as follows:
ROM locations: 3 per location
Speed:  1 per cycle if Error condition
                2 per cycle if Celsius temperature is negative
                3 per cycle otherwise (0 - 37.5 Celsius)
RAM locations: 3 for each temporary RAM needed

Lowest score wins!

The winner gets...... a free copy of PICBots.  ;-)
(For those of you that don't know, PICBots is always free. )

Let the games begin!!!!


| Alan G. Smith

1997\09\27@055100 by Steve Smith

picon face
Just a small thaught :-

Consider using degres Kelvin as then determining the sign is of no importance

Sorry Steve.....Ill try and come up with some thing more constructive next
time !

1997\09\27@114304 by Mike Keitz

picon face
On Fri, 26 Sep 1997 20:13:09 -0400 "Alan G. Smith" <.....agsKILLspamspam@spam@POBOXES.COM>
> It is commonly known that
>   tempF = (9/5)tempC + 32

[a simple 9/5 routine exists, but it only works for positive numbers]

>Celsius temperature will range from -55 to 125.

An obvious answer is to add 60 to the Celsius reading so it is always
positive, do the 9/5 scaling, then subtract 76 (which is 9*60/5 - 32)
from the result.

  tempF = (9/5)(tempC+60) - 76

60 is the smallest number bigger than 55 for which 9/5 works out evenly.
Offsetting celsius by 276 (another one that works out exactly) will
handle temperatures all the way to absolute zero, but then the 9/5
routine might need to be more than 8 bits.

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...