开发者

Converting bytearray to Objective-C data structure [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Byte array in o开发者_如何学运维bjective-c

Am converting some Java code to Objective-C and have run into an issue that I can't get my head around:

public static final byte[] DATA_GENERIC = new byte[] { (byte)0xA0, 0x00, 0x00, 0x00, 0x03,
            0x10, 0x10 };

Does anyone know to convert the above into Objective-C


Here is an example of getting your data into a NSData object.

const unsigned char bytes[] = { 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10 };
NSData *data = [NSData dataWithBytes:bytes length:7];
NSLog(@"%@", data);

Output:

<a0000000 031010>

One major difference from java is you will need to keep track of the number of bytes yourself when working with a raw char array. Once you create the NSData you can access the length.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜