I'm confused on how to store a hex value into NSData. I want the value I will be storing to be 0x0F.
Please could someone give me an example?
You can create an array to hold your hex values and then use that to create the data:
unsigned char bytes[] = {0x0F};
NSData *data = [NSData dataWithBytes:bytes length:1];
This can be rewritten as:
NSData *data = [NSData dataWithBytes:(unsigned char[]){0x0F} length:1];
Here's how I've done that before:
UInt8 j= 0x0f;
NSData *data = [[[NSData alloc] initWithBytes:&j length:sizeof(j)] autorelease];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With