• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trouble with binary data and byte buffers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Trouble with binary data and byte buffers (From: Chase Meadors <email@hidden>)

  • Prev by Date: Re: Trouble with binary data and byte buffers
  • Next by Date: [Moderator] Re: ★★★★ Cocoa project for sale
  • Previous by thread: Re: Trouble with binary data and byte buffers
  • Next by thread: [iPhone] Network connection between 2 iPhones-Can GKVoiceChat be my solution?
  • Index(es):
    • Date
    • Thread