• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting float array to UInt8 for writing to a stream.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Converting float array to UInt8 for writing to a stream.
      • From: Scott Ribe <email@hidden>
References: 
 >Converting float array to UInt8 for writing to a stream. (From: "Michael Purdy" <email@hidden>)

  • Prev by Date: Converting float array to UInt8 for writing to a stream.
  • Next by Date: Re: System Configuration Framework and PPTP (VPN) Connections
  • Previous by thread: Converting float array to UInt8 for writing to a stream.
  • Next by thread: Re: Converting float array to UInt8 for writing to a stream.
  • Index(es):
    • Date
    • Thread