c++ - IEEE float hex 424ce027 to float? -
if have ieee float hex 424ce027, how convert decimal?
unsigned char ptr[] = {0x42,0x4c,0xe0,0x27};
how ?
float tmp = 51.218899;
perhaps...
float f = *reinterpret_cast<float*>(ptr);
although on x86 machine here had reverse byte order of character value wanted.
std::reverse(ptr, ptr + 4); float f = *reinterpret_cast<float*>(ptr);
you might want use sizeof(float) instead of 4 or other way size. might want reverse copy of bytes, not original. it's ugly it.
edit: pointed out in comments, code unsafe creates 2 pointers aliasing same memory of different types. may work on specific compiler & program, isn't guarenteed standard.
Comments
Post a Comment