2012-10-17 63 views

回答

10

下面是如何我已經做了之前:

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

您可以創建一個數組來保存你的十六進制值,然後用它來創建數據:

unsigned char bytes[] = {0x0F}; 
NSData *data = [NSData dataWithBytes:bytes length:1]; 

這可以被改寫爲:

NSData *data = [NSData dataWithBytes:(unsigned char[]){0x0F} length:1]; 
相關問題