iOS 2进制与16进制的转换

2017-03-08  本文已影响112人  jianshu小赵

@implementation NSString (StringToHexData)

//
// Decodes an NSString containing hex encoded bytes into an NSData object

@end
@implementation NSData (DataToHexString)

  • (NSString *) dataToHexString
    {
    NSUInteger len = [self length];
    char * chars = (char *)[self bytes];
    NSMutableString * hexString = [[NSMutableString alloc] init];

for(NSUInteger i = 0; i < len; i++ )
[hexString appendString:[NSString stringWithFormat:@"%0.2hhx", >chars[i]]];

return hexString;
}
@end

上一篇下一篇

猜你喜欢

热点阅读