I have a 64-bit timestamp unpacked from a file with binary data, where the top 32 bits are the number of seconds and the bottom 32 bits are the fraction of the second. I’m stuck with how to actually convert the bottom 32 bits into a fraction without looping through it bit-by-bit.
Any suggestions?
For reference, the number 4ca1f350 9481ef80 translates to 1285682000.580107659
Edit:
For context: the data comes from a packet capture device and the documentation I’ve seen says that it the fractional part has roughly nano-second precision (specifically it outputs 29 of the 32 bits, giving ~2ns).
To represent the sum of integral and fractional part with enough precision (32 + 29 = 61 bits), you need a Decimal (28 decimal digits by default, which is enough for 93 bits),
or Fraction (exact),
Note that a float uses “IEEE double format” so it can only hold 53 bits of precision:
It is fine if you store the fractional part as its own variable, but if that’s the case, why not just keep it as-is?