- NSdata 转换成 字符串
- (NSString *)hexStringFromString:(NSData *)data{
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];
}
return hexStr;
}
网友评论