I am reading a sequence of bytes from a pipe. The data is actually 32 bit float values. Is there an easy and efficient way to convert the byte array to a float array. Just doing asFloatArray not surprisingly gives me an array with each byte converted to a float and what I want is each 4 bytes converted to a float.
Any help appreciated.
Thanks Bob *** Confidentiality Notice *** Proprietary/Confidential Information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply email.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Cowdery, Bob [UK] wrote:
I am reading a sequence of bytes from a pipe. The data is actually 32 bit float values. Is there an easy and efficient way to convert the byte array to a float array. Just doing asFloatArray not surprisingly gives me an array with each byte converted to a float and what I want is each 4 bytes converted to a float.
Any help appreciated.
Thanks Bob
Hi Bob,
If I had the testing file you have, I would try to do this:
Float fromIEEE32Bit: (Integer byte1: stream next byte2: stream next byte3: stream next byte4: stream next)
I assume that `stream next' gives me a single byte. But this need not be the case. But you can try it.
Regards - -- Matej Kosik
Convert these bytes into a 32 bit integer first (e.g., with endian conversion if necessary) and then use Float fromIEEE32Bit: value. And that is of course assuming that your 32bit floats are in IEEE 754 format.
Cheers, - Andreas
Cowdery, Bob [UK] wrote:
I am reading a sequence of bytes from a pipe. The data is actually 32 bit float values. Is there an easy and efficient way to convert the byte array to a float array. Just doing asFloatArray not surprisingly gives me an array with each byte converted to a float and what I want is each 4 bytes converted to a float.
Any help appreciated.
Thanks Bob *** Confidentiality Notice *** Proprietary/Confidential Information belonging to CGI Group Inc. and its affiliates may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message to anyone else. In such case, you should destroy this message and are asked to notify the sender by reply email.
Bob,
I am reading a sequence of bytes from a pipe. The data is actually 32 bit float values. Is there an easy and efficient way to convert the byte array to a float array. Just doing asFloatArray not surprisingly gives me an array with each byte converted to a float and what I want is each 4 bytes converted to a float.
Is it something that #hackBits: can help? Take a look at Bitmap>>copyFromByteArray: and Bitmap>>asByteArray.
-- Yoshiki
squeak-dev@lists.squeakfoundation.org