Re: Trouble with binary data and byte buffers
Re: Trouble with binary data and byte buffers
- Subject: Re: Trouble with binary data and byte buffers
- From: Graham Cox <email@hidden>
- Date: Tue, 14 Jul 2009 15:20:19 +1000
On 14/07/2009, at 3:02 PM, Chase Meadors wrote:
for (int i = 0; i < aNumber; i ++) {
NSLog(@"X", buf[i]);
}
This is what's really bothering me because I'll get normal bytes,
like 2E 00 AA, but sometimes, seemingly randomly, there are six
leading F's. Something like:
0E
00
FFFFFF8E
%X expects an unsigned number but you are passing it a char, which is
signed, so it's sign extending and displaying the result as if the
high bit were a sign bit. You'll notice it's not random, it's whenever
the high bit is set.
Also, your buf should be declared char*, not char, which is why it's
crashing.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden