On Nov 25, 2011, at 7:07 PM, Glenn L. Austin wrote:

> On Nov 25, 2011, at 2:56 PM, Koen van der Drift wrote:
> 
>> On Nov 25, 2011, at 5:44 PM, Scott Ribe wrote:
>> 
>>> As another response suggested, what's wrong with ntohl???
>> 
>> I implemented that function based on some code I found online, but got very 
>> weird results, which is why I asked here.  My knowledge on these esoteric 
>> functions apparently isn't up to par :)
>> 
>> As long as I end up with an array of x,y values, I really don't care how I 
>> get there.  Eventually they will need to end up in an NSArray for further 
>> processing though.
> 
> That function is already implemented on every machine that support networking 
> -- including Mac OS X.  You don't need to implement it yourself -- just 
> #include <arpa/inet.h>
> 
> Do a man ntohl for more info.


I read that but am still confused :(

Here is what I am doing, I read an NSString from the raw data, an xml file 
using NSXMLParser. This works ok.  Then I convert that to an NSData object, and 
perform base64 decoding (using 
http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html):

NSData *data =  [string dataUsingEncoding:NSASCIIStringEncoding];
NSString *base64String = [data base64EncodedString];
NSData * base64DecodedData = [NSData dataFromBase64String:base64String];

I then retrieve chunks of 32 bytes as follows:

NSRange range = {n, 32};
NSData *chunk = [base64DecodedData subdataWithRange:range];

But I am struggling with how to use this with ntohl, similar to the code I am 
trying to implement:

                for (n = 0 ; n < (2 * count) ; n++)
                {
                   ((u_int32_t *) result)[n] = ntohl((u_int32_t) ((u_int32_t *) 
dataToConvert)[n]);
                }

Any help appreciated.  I am happy to send the raw string off-list if anyone 
wants to give it a try. The end results should give pairs of floats:

300.066772460938
1201.86157226562

301.141448974609
45845.18359375

301.215972900391
1430.0322265625

etc


Thanks,

- Koen.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to