Skip to main content
Associate II
Nov 25, 2026 14:40 UTC
Question

Float conversion results in vastly LARGER number

Im doing a float conversion on an stm32h7, IDE is stm32cubeide v2.2.0 and using GNU tools for stm32 14.3rel1.

When i step through my code, I perform a conversion TO a float from an int32_t. The converted value (in decimal format, viewing via the Variables view in the debugger) is WAY bigger than the int32_t i put in. Here is the code along with all my attempts to eek out every piece of info i could:

static void MIC_Capture_Process(const int32_t *raw)
{
uint32_t wr = mic_ring_wr;
uint32_t rd = mic_ring_rd;
uint32_t i = 0;
float x = 0;
float y = 0;
float scaled = 0;
int16_t out = 0;
int16_t mag = 0;

int32_t raw_at_i;
int32_t raw_at_i_shifted;
float raw_at_i_shifted_f_1, raw_at_i_shifted_f_2;
int32_t a1,a2,a3,a4,a5;

for (i = 0U; i < MIC_CAPTURE_DMA_HALF_SAMPLES; i++)
{
raw_at_i = raw[i];
a1 = (int32_t)&raw_at_i;
raw_at_i_shifted = raw[i] >> 8;
a2 = (int32_t)&raw_at_i_shifted;
raw_at_i_shifted_f_1 = (float)raw_at_i_shifted;
a3 = (int32_t)&raw_at_i_shifted_f_1;
raw_at_i_shifted_f_2 = (float)(raw[i] >> 8);
a4 = (int32_t)&raw_at_i_shifted_f_2;
x = (float)(raw[i] >> 8); /* Signed 24-bit sample; drop channel/status bits. */

We pass in a pointer, raw, and then take a value within that array and shift it then convert it. The shift works fine. Things get weird at raw_at_i_shifted_f_1 = (float)raw_at_i_shifted; Right now, im paused in my debugger at x = (float) blah blah blah. The value for raw_at_i_shifted is reportedly 5134972 (decimal). The value for raw_at_i_shifted_f_1 is reportedly 1251783928 (decimal). I have double checked the viewing window to make sure they ARE decimal. Any help here would be wonderful.