On Nov 27, 2011, at 6:06 AM, Koen van der Drift wrote:

> Again giving the same expected results.  Would this be the correct call, or 
> am I still missing something?

The purpose of casting? I think you need to review a C reference, you're 
casting a uint32_t to uint32_t * then back to uint32_t. In prior code you were 
casting something (unsigned char * ???) to uint32_t *, then dereferencing it, 
which would be a uint32_t, then casting that to a uint32_t.

NSData *base64DecodedData = [NSData dataFromBase64String: 
@"Q5YIjESWO5JDlpIbRzMVL0OW="];
int n = [NSData length] / 4;
const uint32_t *buf = (const uint32_t *) [NSData bytes];
float *results = (float *) malloc(n * 4);
for( int i = 0; i < n; ++i )
        ((uint32_t *)results)[n] = ntohl( buf[n] );

Two of the casts, of bytes & malloc results, are not necessary in plain C, but 
they're required in C++ and are habit for me ;-)

Of course you might want to check that sizeof( float ) is 4, but the prior 
suggestion to use it in the code in place of 4 is off, because your input will 
still be 4 bytes I presume, and if your platform float is not 4, then you can't 
make it work and have to fail. (Of course, if your platform doesn't adhere to 
IEE floating point standards, and your input does, or vice versa, you're 
screwed anyway.) You might want to check that the data length is an exact 
multiple of 4, or rather 8 since you're expecting floats in pairs. And so on...

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




_______________________________________________

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