This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

conversion of hex data to float inverse

Other Parts Discussed in Thread: MSP430G2553

I am trying to communicate a electric meter using rs485 and msp430g2553 microcontroller. The meter sends hex data, now i want to convert hex data into inverse float value. Is there any library function or function command to do that.

For eg : Hex data is {0x43,0xCF,0x80,0x00}   // inverse float value is 415.0

How to convert it into  float value.

  • "Hex" and "binary" are two different concepts.

    This looks like a big-endian float; just reverse the order of the bytes, and treat the memory as a float. And what do you mean with "inverse"?

  • Hello
    sorry it was only float as u said it is big endian so i wrote it down as inverse.
  • Hi Harish!

    You could, for example, use a function like this:

    float hex_to_float( uint8_t * hex_array );
    
    uint8_t float_in_hex[4] = { 0x43, 0xCf, 0x80, 0x00 };
    float   float_from_hex;
    
    ...
    
    void main( void )
    {
      ...
    
      float_from_hex = hex_to_float( float_in_hex );
    
      ...
    }
    
    float hex_to_float( uint8_t * hex_array )
    {
      float     result;
      uint8_t   counter;
      uint8_t * pointer;
    
      pointer = (uint8_t *) &result;
    
      for( counter = 0; counter < sizeof( float ); counter++ )
      {
        *(pointer + counter) = *(hex_array + sizeof( float ) - 1 - counter);
      }
    
      return result;
    }

    Dennis

**Attention** This is a public forum