• 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
Trouble with binary data and byte buffers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble with binary data and byte buffers


  • Subject: Trouble with binary data and byte buffers
  • From: Chase Meadors <email@hidden>
  • Date: Tue, 14 Jul 2009 00:02:16 -0500

Hi, I'm having some confusion here over displaying raw binary data.

I have my NSMutableData object that I'm getting the bytes from. As I understand it, there are different ways to get the bytes.

The -getBytes:range: method

NSRange r = NSMakeRange(x, y);
char buf[y];
[data getBytes:&buf length:r];

Or the -bytes or -mutableBytes methods

char buf = [data bytes];


What is the generally accepted method of doing this? I'm using the first method, as the other one sometimes crashes.



Second, I'm testing the data with the following code:

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
AA
FF
4E
FFFFFF0C
FFFFFF9A
9C
C0

Viewing the data in a hex editor reveals that the values on the end of these F's are correct. For some reason, the data is just preceded by extraneous F's...

Any help appreciated, thanks!


_______________________________________________

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


  • Follow-Ups:
    • Re: Trouble with binary data and byte buffers
      • From: Graham Cox <email@hidden>
    • Re: Trouble with binary data and byte buffers
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: [iPhone] Addressbook "group" problem
  • Next by Date: Re: Trouble with binary data and byte buffers
  • Previous by thread: Re: spaghetti code with core data and multiple views
  • Next by thread: Re: Trouble with binary data and byte buffers
  • Index(es):
    • Date
    • Thread