cancel
Showing results for 
Search instead for 
Did you mean: 

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

SVerm.3
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AVI-crak
Senior

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.

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