NSData 與 ByteNSData-> Byte數組
NSString *testString = @"1234567890";
NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
Byte *testByte = (Byte *)[testData bytes];
for(int i=0;i<[testData length];i++)
printf("testByte = %d\n",testByte[i]);
Byte數組-> NSData
Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
NSData *adata = [[NSData alloc] initWithBytes:byte length:24];
Byte數組->16進制數
Byte *bytes = (Byte *)[aData bytes];
NSString *hexStr=@"";
for(int i=0;i<[encryData length];i++){
? ? NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff];///16進制數
? ? if([newHexStr length]==1){
? ? ? ? hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
? ? }else {
? ? ? ? hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
? ? }
}