Re: Converting float array to UInt8 for writing to a stream.
Re: Converting float array to UInt8 for writing to a stream.
- Subject: Re: Converting float array to UInt8 for writing to a stream.
- From: Wade Tregaskis <email@hidden>
- Date: Fri, 12 Nov 2004 11:28:47 +1100
I've got a prototype moving forward to connect a client to a server
(many thanks to Suraj). Next, I need to take data from an array of
floats and send it to the server via CFWriteStreamWrite. I need to
convert it go a buffer of UInt8 I think. Then after getting a return
stream from the server, I will need to convert back to the array.
Are there any CF functions to do this or any resources which may show
how to do so efficiently, that any list members are aware of?
Well, you'll want to look at
<http://developer.apple.com/documentation/CoreFoundation/Reference/
CFByteOrderUtils/index.html> for byte swapping. To then convert
between types, try something like:
union {
float real;
uint8_t bytes[sizeof(float)];
} convert;
convert.real = myValue;
memcpy(destination, convert.bytes, sizeof(float));
Note that you cannot just type-cast between types, since that will
attempt to perform a conversion of some sort, which may or may not give
you what you ultimately want.
Obviously to convert to back, just copy your data into convert.bytes
and read convert.real (after performing any necessary byte-swapping).
Wade Tregaskis (AIM, Yahoo & Skype: wadetregaskis, ICQ: 40056898, MSN &
email: email@hidden, Jabber:
email@hidden)
-- Sed quis custodiet ipsos custodes?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden