Search code examples
arduinodecimalsensorsfixed-point

What's the used format for decimals in the dht11 sensor?


I am using a dht11 sensor and get the raw bits, where the first 8 Bits are the integral of humidity and following 8 bit the decimals of the humidity. The next 8 Bits are the the integral of temperature, followed by 8 bit decimals of the temperature. In the end there is a 8 bit checksum.

I read some datasheets, but could not find any information about how the decimals have to be read.

Does anyone know if it is a simple fixed-point 8 Bit decimals or do I have to do it differently?

Any help is appreciated


Solution

  • From the dht11 datasheet, only positive values for humidity and temperature can be returned, so no bit reserved for the sign. This is a Q8.8 fixed point representation (see also https://en.wikipedia.org/wiki/Q_(number_format)). To translate from the representation to the physical value you have to divide by 2^8, where 8 is the number of fractional bits. So for example:

    0000 0010 1000 0000 = 640 decimal
    640/256 = 2.5 decimal