Skip to content

Instantly share code, notes, and snippets.

@advantis
Created November 25, 2013 10:22
Show Gist options
  • Save advantis/7639299 to your computer and use it in GitHub Desktop.
Save advantis/7639299 to your computer and use it in GitHub Desktop.
NSData category for generating hexadecimal string representation
//
// Copyright © 2012 Yuri Kotov
//
#import <Foundation/Foundation.h>
@interface NSData (ADVHexadecimalRepresentation)
- (NSString *) hexadecimalRepresentation;
@end
//
// Copyright © 2012 Yuri Kotov
//
#import "NSData+ADVHexadecimalRepresentation.h"
@implementation NSData (ADVHexadecimalRepresentation)
- (NSString *) hexadecimalRepresentation
{
const char *bytes = [self bytes];
NSUInteger length = [self length];
NSMutableString *string = [NSMutableString stringWithCapacity:(2 * length)];
for (NSUInteger i = 0; i < length; ++i)
{
[string appendFormat:@"%02hhx", bytes[i]];
}
return string;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment