I have a problem interpretting the temperature reading of a DS18B20 chip. There is a certain situation I am not abble to resolve. This is the example temp table for the chip from the datasheet: enter image description here

an example for reading of -0.5*C is shown as FFF8. Cutting off the 4 LSBits we get 0x0FFF. In signed data structure that is equal to -1, not 0. How am I abble to resolve the difference between 2 readings: -0.5*C and -1.5*C? If 0xFFF8 = -0.5 then what is the form of -1.5?

The table then shows an example for -10.125*C. Cutting off the 4 LSBits gives 0x0FF5 which really is -10, then there is no reason to think that there is some kind of a shift for reading negative values...

  • \$\begingroup\$ When you cut off the low four bits you are losing the fractional part of the temperature reading. So -0.5 looks like -1.0 because the scale of the highest order of the low four bits that you lopped off are effectively >= 0.5 rounds up to next integer (either positive or negative). \$\endgroup\$ Dec 29, 2014 at 13:05

1 Answer 1


You don't shift, you divide.

The value is a simple 16-bit signed integer that is 16 times larger than the temperature. Just assign the value to a 16-bit integer, then divide it by 16.0 as a floating point number:

int16_t min5s = 0xFF5E;
double d = (double)min5s / 16.0;
printf("%g\n", d);

>>> -10.125

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.