On Nov 26, 2011, at 4:23 PM, Scott Ribe wrote:

> No, you're not ;-) You read a string that is presumably already Base64 
> encoded, then you stuff it into an NSData, then you Base64 encode that, then 
> you decode it, leaving you with the original Base64 encoding intact...
> 
> Instead of:
> 
>> NSData *data =  [string dataUsingEncoding:NSASCIIStringEncoding];
>> NSString *base64String = [data base64EncodedString];
>> NSData * base64DecodedData = [NSData dataFromBase64String:base64String];
> 
> I think you just need:
> 
> NSData * base64DecodedData = [NSData dataFromBase64String:string];

I think you are right.  This works (see below).  Thanks for pointing (no pun) 
that out.

> The actual byte-swapping code looks OK:
> 
>>               for (n = 0 ; n < (2 * count) ; n++)
>>               {
>>                  ((u_int32_t *) result)[n] = ntohl((u_int32_t) ((u_int32_t 
>> *) dataToConvert)[n]);
>>              }
> 
> Although there's a superfluous cast there that might be a clue that you're 
> just slinging code in without understanding it...


I'm pretty sure I messed up something. One of the reasons I posted it here :) 

After spitting through the internets, what I am using now is this:

        NSData *base64DecodedData = [NSData dataFromBase64String: 
@"Q5YIjESWO5JDlpIbRzMVL0OW="];
            
        for (NSInteger n = 0; n < 4; n++)
         {
                u_int32_t value;
                [base64DecodedData getBytes: &value range: NSMakeRange( n*4, 
sizeof( u_int32_t ) )];
                
                u_int32_t result = CFSwapInt32HostToBig( value );
                NSLog(@"%u", result);
        }

This gives:

1133906060
1150696338
1133941275
1194530095

This correspond to the values I am getting using the unpack function in a Perl 
script that does what I need, so I think I am on the right track. The perl 
script continues with $float = unpack("f", pack("I", $i));,  where $i is one of 
the four numbers above.  This gives the expected values for the floats.  So I 
may not need the ntohl() function at all.

Now I need to figure out how to go from u_int_32 to float.

- 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