Converting bytearray to Objective-C data structure [duplicate]
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.
精彩评论