Tom Gonser
- 5th March 2005, 19:18
Probably a 'newbie' error, but it has me cornered...
I have a routine that is trying to take degrees C and convert to degrees F.. However the math is not working.
Here is how it works:
1.) I take data into an array and read that data tha deals with temperature and convert from hex to decimal
' read data for temperature Temp
SSD4= (ssmax[24]>>4)
SSD3= (ssmax[24] & $f)
SSD2= (ssmax[23]>>4)
SSD1= (ssmax[23] & $f)
' convert to Decimal:
Dec_temp=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1
2) I read these values out into a screen to show degrees (C), then write it out to the screen:
serout2 cpinout, 84,["Temp(C): ",#Dec_temp dig 3, #Dec_temp dig 2,#Dec_temp dig 1, ".",dec1 Dec_temp]
THIS WORKS FINE.. I get the proper 'Degrees C'...
"Temp(C): 025.5 " shows up in HyperTerminal. No problem..
BUT! Here is where it gets funky.. What if I wanted to see Degrees F?
3) I multiply:
Dec_tempf=(Dec_temp*(9/5) + 32) ' convert to farenheit
And output with this:
serout2 cpinout, 84,["Temp(F): ",#Dec_tempf dig 3, #Dec_tempf dig 2,#Dec_tempf dig 1, ".",dec1 Dec_tempf]
The display The same serout2, but now in (F)
It shows "Temp(F): 025.5" - What the heck?? That is the same as (C)???
So then I decide to look at the numbers underneath:
First - theBase # is "223" This is the value in #Dec_temp
Then look at the math:
Testmath1 - (Dec_temp*(9/5)+32) = 255 -- this is wrong
Or even look at **:
Testmath2 - (Dec_temp**(9/5)+32) 32 -- still odd..
Can anyone solve this puzzle?
Thanks
Tom
I have a routine that is trying to take degrees C and convert to degrees F.. However the math is not working.
Here is how it works:
1.) I take data into an array and read that data tha deals with temperature and convert from hex to decimal
' read data for temperature Temp
SSD4= (ssmax[24]>>4)
SSD3= (ssmax[24] & $f)
SSD2= (ssmax[23]>>4)
SSD1= (ssmax[23] & $f)
' convert to Decimal:
Dec_temp=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1
2) I read these values out into a screen to show degrees (C), then write it out to the screen:
serout2 cpinout, 84,["Temp(C): ",#Dec_temp dig 3, #Dec_temp dig 2,#Dec_temp dig 1, ".",dec1 Dec_temp]
THIS WORKS FINE.. I get the proper 'Degrees C'...
"Temp(C): 025.5 " shows up in HyperTerminal. No problem..
BUT! Here is where it gets funky.. What if I wanted to see Degrees F?
3) I multiply:
Dec_tempf=(Dec_temp*(9/5) + 32) ' convert to farenheit
And output with this:
serout2 cpinout, 84,["Temp(F): ",#Dec_tempf dig 3, #Dec_tempf dig 2,#Dec_tempf dig 1, ".",dec1 Dec_tempf]
The display The same serout2, but now in (F)
It shows "Temp(F): 025.5" - What the heck?? That is the same as (C)???
So then I decide to look at the numbers underneath:
First - theBase # is "223" This is the value in #Dec_temp
Then look at the math:
Testmath1 - (Dec_temp*(9/5)+32) = 255 -- this is wrong
Or even look at **:
Testmath2 - (Dec_temp**(9/5)+32) 32 -- still odd..
Can anyone solve this puzzle?
Thanks
Tom