Yes. The method above works well. I did not try the other way to see if it's tighter code though, I was happy to just push onwards.
I discovered a issues with the rest of my calculations though, and I'd appreciate a comment from the 'Long literates' among us.
I'll try to explain without a huge dialogue, if it's too vague let me know. Here goes...
OK, this code, all the variables are Longs, except AC5, AC6 and MD which are Words.
Code:
X1 = ((lUtemp - AC6) * AC5) >>15 'find X1 - Note I needed the extra () around AC5 to get it to work
X2 = (lMC << 11) / (X1 + MD) 'Find X2
B5 = X1 + X2 'Find B5 from X1 and X2
lCTemp = (B5 + 8) / 16 '>> 4 'Hey presto, lCTemp appears...
Firstly I needed two sets of parenthesis around the X1 calculation, or it gave a bad result with only one around the 'lUTemp -AC6'.
The original C code was like this though ( I changed the 2^15 to the shift right by 15).
X1 = (UT - AC6) * AC5 / 2^15
Second, in the last calculation, I got a bad result whenever the value B5 became negative, until I got rid of the >> 4 and made that a '/ 16'. Then the value of lCTemp worked OK below 0 degC (I used freezer spray). I thought a >> 4 shift was equivalent to a / 16, but here in this syntax it seems not.
Can someone fill me in on why the shifts didn't quite work like a numeric divide here ?
Perhaps something to do with signed math again ?
In the end with the second brackets and a numeric divide the results were good, I'd just like to know why my 'fixes' worked so I don't bugger up the next stage...
Thanks,
Martin
Bookmarks