arrays - Convert a hexadecimal to a float and viceversa in C - Stack Overflow

PHOTO EMBED

Tue Nov 15 2022 00:53:41 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu #c

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

int main(void) {
  char myString[]="0x3f9d70a4";
  uint32_t num;
  float f;
  sscanf(myString, "%x", &num);  // assuming you checked input
  f = *((float*)&num);
  printf("the hexadecimal 0x%08x becomes %.3f as a float\n", num, f);
}
content_copyCOPY

https://stackoverflow.com/questions/21323099/convert-a-hexadecimal-to-a-float-and-viceversa-in-c