Store hex value in NSData

I am confused about how to store a hex value in NSData. I want the value that I will be storing to be 0x0F .

Please can someone give me an example?

+4
source share
2 answers

Here's how I did it before:

 UInt8 j= 0x0f; NSData *data = [[[NSData alloc] initWithBytes:&j length:sizeof(j)] autorelease]; 
+10
source

You can create an array to store hexadecimal values, and then use it to create 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]; 
+11
source

Source: https://habr.com/ru/post/1440228/


All Articles