简体   繁体   English

如何将原始字节写入NSMutableData对象?

[英]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: 假设我想将以下字节添加到NSMutableData对象:

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. 我想这与appendBytes:length:方法有关,但老实说我不知道​​如何将上面的内容转换为NSMutableData。

Any help would be greatly appreciated! 任何帮助将不胜感激!

This should do it: 这应该这样做:

NSMutableData *data = [NSMutableData data];
char bytesToAppend[5] = {0x01, 0xf0, 0x64, 0x0, 0x6a};
[data appendBytes:bytesToAppend length:sizeof(bytesToAppend)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM