in reply to Re: Converting bytes to floats
in thread Converting bytes to floats

It's a series of bytes. This powershell works:
$len = $bytes.Count/8 for( $i = 0 ; $i -lt $len ; $i++) { [System.BitConverter]::ToDouble($bytes, $i * 8 ) }

Replies are listed 'Best First'.
Re^3: Converting bytes to floats
by ikegami (Patriarch) on Apr 18, 2023 at 04:08 UTC
      Did you try what I provided?

      I think it's theoretically possible that the OP did follow the advice but struck an endianness issue which, to be resolved, would presumably require either:
      unpack "d<*", $contents or unpack "d>*", $contents
      Cheers,
      Rob

        If they're dealing with non-native architectures, they might have bigger problems than endianness. Unpack will only be useful if the both platforms use the same format for floats.

        I assumed they are on an x86 or x86-64, as I would have expected them to mention it if it wasn't the case.

        I also assumed that they were referring to IEEE double-precision floats. Though I did give them the information they needed for IEEE single-precision floats too via the link.

        struck an endianness issue

        Man, this takes me back several years to when I started coding low-level stuff for my microcontroller sensor projects.

        Collecting data and flipping bits...fine, but swapping entire bytes!?! :)

Re^3: Converting bytes to floats
by harangzsolt33 (Deacon) on Apr 17, 2023 at 23:39 UTC
    Yes, I think, what you are looking for is $number = unpack('d', $bytes);

    If $bytes hold 8 bytes, then unpack will convert that to a number.