11

Ok, I'm a little stumped here, as I've never really dealt with anything this low level. Say I want to add the following bytes to an NSMutableData object:

0x01, 0xF, 0x64, 0x0, 0x6A

How do I even go about doing this? I imagine it's something to do with the appendBytes:length: method, but I honestly don't know how to transform what I have above into an NSMutableData.

Any help would be greatly appreciated!

Kyle Slattery
  • 33,318
  • 9
  • 32
  • 36
  • Maybe http://stackoverflow.com/questions/2338975/convert-hex-data-string-to-nsdata-in-objective-c-cocoa and http://stackoverflow.com/questions/4917968/best-way-to-generate-nsdata-object-with-random-bytes-of-a-specific-length can help you... – Pooria Azimi Mar 14 '12 at 16:08

1 Answers1

23

This should do it:

NSMutableData *data = [NSMutableData data];
char bytesToAppend[5] = {0x01, 0xf0, 0x64, 0x0, 0x6a};
[data appendBytes:bytesToAppend length:sizeof(bytesToAppend)];
Andrew Madsen
  • 21,309
  • 5
  • 56
  • 97