Cyclic Redundancy Check:
To ensure any detection of raw data modification (corruption) of sensor(HTU21DF) measurement, Cyclic Redundancy Check is used. Polynomial used for CRC is
Above polynomial can be written as
taking coefficients of all terms our binary values are 1 0 0 1 1 0 0 0 1. This binary value or polynomial generator is used a divisor for CRC computations.
Compute checksum: (Best refer to Wikipedia link ) or there are readymade tools. But if you are interested to know below are steps..

Step 1: Take input bytes from Sensor (MSB + LSB as detailed in previous post). They are 16 bits longs (2 bytes). Append to them 0’s 8 to right (should be equal to length of polynomial generator). <Update> As we are stuffing 0 to right of data bytes, effectively “Left Shift” operation occurs.

Start from left most bit that has bit value of 1 and perform an XOR bitwise operation with polynomial generator. Skip any 0s in middle and perform operations if bit left most is 1.

Repeat these operations moving Polynomial generators to right, where bit value is 0 till 16 bits.

In Step 1, due to polynomial movement, initially stuffed 0’s will have changed to different state and that result is output of CRC computation.
As an example, in previous example measured humidity is 31827 when converted to binary is input. Using polynomial generator in an iterative manner compute CRC. Sample computations are below.
In this manner, receiving application can compute CRC for MSB and LSB compare with CRC byte to check if data received is not corrupted.
Post measure and performing CRC checks, formula need to applied to raw measurements to arrive at accurate values as provided in manual.
Relative Humidity Conversion:
Where S(RH) is Humidity Signal Output that is measured from Sensor.
Relative Humidity Conversion:
With this HTU21DF sensor internals are complete… As continuation to this series of blog, follow up blog will detail how to programmatically get data out Sensor using RASPBERRY PI 2 MODEL B and SPARKFUN WEATHERSHIELD that includes HTU21DF sensor…
Until next post…
–Abhyast