Hi,
I'm doing bit-packing via a C function. Logging the bits of the C function
shows the expected result. If I create a string with a hex value format, I get
the correct hex string, but, if I try to put the bytes into an NSData object
with [NSData dataWithBytes: length], the order of the bits changes. All of the
right elements are there, but they're in the wrong order (target data should be
f0000651, as shown in the Target string is ... log).
My code:
// get the target int from the text field
unsigned int tgtValue = [self.tgtTF intValue];
// use the target int and type to pack the bits into an int
uint32_t tgtBinary = setAnalogValueForIndex(cid, tgtValue);
NSString *tgtString = [NSString stringWithFormat:@"%x", tgtBinary];
NSData *tgtData = [NSData dataWithBytes: &tgtBinary length:
sizeof(tgtBinary)];
NSLog(@"Target data is %...@. Target string is %@", tgtData,
tgtString);
The logs:
11110000000000000000011001010001
2009-11-30 11:02:26.126 CertTest[11959:a0f] Target data is <510600f0>. Target
string is f0000651
2009-11-30 11:02:26.204 CertTest[11959:a0f] After adding target, cmdData is
<510600f0>
If NSData is rearranging the bits, is there some way to prevent this?
Thanks.
Brad
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]