Picaxe math restriction

rbright

Member
Pixaxe will only allow integer calculation and then only with values less than 65535.

I'm trying to process some negative temperature values from a DS18B20 and I need to divide by a fraction as follows:

I have 16 bit word W1 which contains FF5E. I want to subtract that from FFFF then divide the result by 0.0625.

Any ideas
 

MPep

Senior Member
Do a forum search.
I found the following
Code:
It's will return anything between -55 to 125ºc

The positive values will be returned directly such as b1 = 25

The negative values will be everything bigger than 127. In this case, you'll have to substract 128 from this value.

Having that, you can have something like.

b1 = 140

So, b1 = 140 - 128

Then b1 = 12

That means you have -12ºc
Okay, this is for 8bits only but you get the idea.:D

2's complement is used here.
 

rbright

Member
Now Working - see other post today

Thanks for the hints to use 2's Compliment - of course that is what the DS18B20 was expecting to have to process it's negative values. I've just posted on another thread the resulting code as a bit of a tutorial for others but with lots of comments
 
Top