开发者

Converting bytearray to Objective-C data structure [duplicate]

开发者 https://www.devze.com 2023-03-20 05:22 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Byte array in o开发者_如何学运维bjective-c
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

精彩评论

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