Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write raw bytes to an NSMutableData object?

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!

like image 463
Kyle Slattery Avatar asked Mar 14 '12 15:03

Kyle Slattery


1 Answers

This should do it:

NSMutableData *data = [NSMutableData data];
char bytesToAppend[5] = {0x01, 0xf0, 0x64, 0x0, 0x6a};
[data appendBytes:bytesToAppend length:sizeof(bytesToAppend)];
like image 181
Andrew Madsen Avatar answered Sep 28 '22 00:09

Andrew Madsen