yes, it is the difference between lossless compression and lossy compression.

There can other ways to improve run-length compression, without data loss , but they involve knowing a bit about the data.

**Method 1:**Assumption: The temperature is always between 10 and 40. That can be encoded in 5 bits 0..31 this leaves 3 bits for runlength .

The runlength 0..7 can represent 1..8 (as 0 is not needed).

[010 01100] = 3x (12+10) = 3x22C

this way you can encode temperature in one byte. However if the runlength is larger than 8 you have a problem.

But that can be solved in the following way.

We offer the runlength 8 = [111 xxxxx] and give it the meaning, He I am a runlength that is not 8 but the next byte is the real runlength (original model).

example :

`[010 01100] [010 01101] [111 01100] [0001 0000] [010 01101]`

3 x 22 2 x 23 !! 22 (16 x) 3 x 23Get the idea?

**Method 2:**If the range of temperatures is larger than 32 C you can do

**delta encoding**.

Do not store the temperature, but the difference between the current and the previous value. With 4 bits you can encode jumps from -7 to +8 (OK zero would not be needed) This will be acceptable in most applications. (otherwise take 5 bits for the delta, like above)

This leaves 4 bits for the run length 1..14

- 0, has the special meaning, that the next byte is an absolute temperature

- 15, has the special meaning that the next byte is the actual run length

[ 0000 5 ] [32] abs temp = 32 (5 x) - the place where normally is the temp now a run length is coded

[ 2 1 ] 2x 33

[ 4 2 ] 4x 35

[16 -1 ] [120] NEXT BYTE = RL. ==> 120 x 34

[3 -1 ] 3x 33

[ 0 4 ] [24] new abs temp = 24 (4x)

The compression and decompression will become a bit more complex but very doable.

By placing an absolute marker every 20 readings you can even recover most of the data in a corrupted file,

as these abs temperatures give a new reference point.

if only one in 20 records need a second byte this compresses the RLE by another ~45%. (at the expense of bigger code!)

Your turn to implement the above ideas