uint32_t to double with negative result not working

290 Views Asked by At

I have a uint32_t that needs to be translated into a signed float or double.

I have tried converting to 2s compliment and divding by the resolution, but when I print the value, the negative sign is not shown, but the absolute value seems to be correct.

I converted to 2s compliment and adjusting resolution by by (~a +1) / 10000000 and storing to a new double variable

However, the negative sign doesn't come through For example, 0xB9EB02A8 converts to 11757806960 and is missing the minus sign.

Any ideas?

#include <stdio.h>
#include <stdint.h>


int main(void)
{
    double lat;
    uint32_t dataWord0 = 0xb9eb04f2;
    lat = (~dataWord0 + 1);
    printf("%f",lat);
}

Output: 1175780110 Should be: -1175780110 then the decimal place needs to be moved to the left by 7 places to show the correct value of -117.5780110

0

There are 0 best solutions below