Skip to main content
SVerm.3
Associate III
March 18, 2021
Solved

How to convert HEX to Float Mid-Little Endian (CDAB) in STM32CubeIDE?

  • March 18, 2021
  • 2 replies
  • 3172 views

Please guide me how to convert HEX to float Mid-Little Endian (CDAB) for example data[3]=0x6A, data[4]= 0x32, data[5]= 0x1B, data[6]= 0x94. Pleasew guide me as soon as possible I am in trouble.

This topic has been closed for replies.
Best answer by Tesla DeLorean

float foo = *((float *)&data [3]);​

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
March 18, 2021

float foo = *((float *)&data [3]);​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
SVerm.3
SVerm.3Author
Associate III
March 18, 2021

Sir You are the best.... I am really highly grateful.May God ​bless you always!!!!

AVI-crak
Senior
March 18, 2021

data [3] = 0x6A; -Very similar to the uint8_t data [x] array. In this case, "0x6A" is a symbolic representation of the stored value in HEX format. In this case, it is enough to reverse the byte order, align the result at the address.

float ss(uint8_t* data){
union {float out; uint8_t in[4];}sse;
sse.in[3]=*(data++);sse.in[2]=*(data++);
sse.in[1]=*(data++);sse.in[0]=*(data++);
return sse.out;
}

However, if the data is written to a file with the NEX extension, then parsing is required. There, 2 bytes of character data in char format are spent for one byte of data, + additional information for each data line. And yet, there are several dozen "HEX" data storage / transmission formats. You need to decide what you are dealing with. The easiest way to do this is by opening the file in binary representation, because editors and IDEs automatically hide the file markup.