#include int main(int argc, char * argv[]) { int a = 0x3f800000; std::cout << a << std::endl; static_assert(sizeof(float)
Use memcpy:
memcpy
memcpy(&f2, &a, sizeof(float));
If you are worried about type safety and semantics, you can easily write a wrapper:
void convert(float& x, int a) { memcpy(&x, &a, sizeof(float)); }
And if you want, you can make this wrapper template to satisfy your needs.