DATA 转 16 进制
// 转 16进制 编码
NSData *data = [NSData dataWithBytes:(const void *)dataOut length:(NSUInteger)dataOutMoved];
Byte *bytes = (Byte *)[data bytes];
// 下面是Byte 转换为16进制。
NSString *hexStr = @"";
for(int i = 0;i < [data 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];
}
}
// 转成大写
for (NSInteger i = 0; i < hexStr.length; i++) {
if ([hexStr characterAtIndex:i] >= 'a' & [hexStr characterAtIndex:i]<='z') {
char temp = [hexStr characterAtIndex:i] - 32;
NSRange range = NSMakeRange(i, 1);
hexStr = [hexStr stringByReplacingCharactersInRange:range withString:[NSString stringWithFormat:@"%c",temp]];
}
}
NSLog(@"hex = %@",hexStr);