Convert one float value into another float value

I am reading a 8 different values from a chip (0.0 to 0.224 in 0.32 steps) every step is 0.125 in °C.
I am a beginner with programming. Where is the mistake in my code?

float getKomma(float g){   //  z.B. 0.192 = 0.750
  float ausgabe = 0.0;
  float tmp = g;   
  float richtig = 0.0;

  if(richtig == tmp)
    ausgabe = 0.0;

  while(richtig != tmp) {
      
      if(tmp == richtig)
        ausgabe = 0.0;

    richtig = (0.0 + 0.32);
    ausgabe = (0.0 + 0.125);
    } 
}

Please post a complete sketch that illustrates your problem and describe fully what the problem actually is

What does it mean?!
If while condition is true, the "if" cannot be true

which chip, how do you read that ?

It makes no sense

1 Like

What is the code supposed to do?

I found a solution with bit manipulation.
The code was supposed to convert 0 -> 0, 32 -> 125, 64 -> 250, ... 224 -> 875
The IC gives it out as 1 byte.
For example the 64 = 01000000 | 160 = 10100000

The funktion getKomma was able to do it in the end but the bit manipulation is much easier.

´´´´
int16_t var = to >>5;
int16_t tmp = var * 125;

´´´´

glad you solved It but, your question and the details will remain a total mystery for the forum :slight_smile:

The slave returns the values (0, 32, 64, 96, 128, 160, 192, 224).
The values I wanted are 0.125 for 32, 0.250 for 64, and +0.125 for the next one.
The IC put the 1 on the 3 hightest bit values (1110 0000).
I tought it would be an idea to convert each IC-Value with a funktion.

so seems you get eight bytes back from an unknown IC, in an unknown communication protocol which can take a limited number of values (0, 32, 64, 96, 128, 160, 192, 224)

we made progress :slight_smile:

If that is the case then for any value greater than zero the value returned could be divided by 32 and the result used to calculate the required output by means of multiplication or using it as a lookup to an array

That's how OP does it :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.