This is an old topic but since it is so complete I did not start a new thread.

I just want to add a couple points. First, because integer division truncates towards zero (floor for positive integers, ceiling for negative integers), you need to reverse the rounding element for negative numbers.

So to support negative numbers, this:

return (celsius * 18 + 5)/10 + 32;

should be

if (celsius < 0) return (celsius * 18 - 5)/10 + 32; else return (celsius * 18 + 5)/10 + 32;

Second, the averaging during conversion is very clever. I like it if your ADC does not have resolution better than 1 degree celsius. Otherwise, if it does have better resolution, I recommend keeping the temperature in tenths degrees celsius and converting from that. Then you don't need the averaging in the conversion. So the above would become, where tdc is tenths degrees celsius:

if (tdc < 0) return (tdc * 18 - 50)/100 + 32; else return (tdc * 18 + 50)/100 + 32;

Roger