You say that 0x98 0xf9 0x38 0x4e 0x3a 0x9f 0x1c 0x43
is supposed to represent 2014093029293670
.
This is true if the former is the little-endian representation of that integer in IEEE754 binary64 format. So your approach by using byte-by-byte multiplication (or equivalently, bit shifts) is not going to work, because those are arithmetic operations.
Instead you need to alias that representation as a double
. To do this portably, on a little-endian machine on which double
is IEEE754 binary64:
static_assert( sizeof(double) == 8 );
double out;
memcpy(&out, buf, sizeof out);
If you want this code to work on a machine with different endianness then you will need to rearrange buf
before doing the memcpy
. (This is assuming that the representation is always obtained in little-endian format, which you didn't state).