objective c 不一樣數據類型轉換

  1. NSString 轉 byte字節數組

    NSData *strDataBytes = [@"$$" dataUsingEncoding:NSUTF8StringEncoding];app

    轉換結果爲{0x24, 0x24};spa

  2. int 轉 bytestring

    NSMutableData *myData = [[NSMutableData alloc] init];it

    int num = 1024;table

    [myData appendBytes:&num length:sizeof(num)];coding

  3. Byte數組 轉 NSDatatab

    Byte *bytes = {***};di

    NSData *strData = [NSData dataWithBytes:bytes length:strlen];
    encoding

  4. NSData 轉 NSString

    NSData *strData = ***;

    NSString* string = [[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding];

相關文章
相關標籤/搜索