Is it possible to NSLog NSData in base 10. Basically to see byte array of NSData.
I would like to see output something like this: [51, -55, 55, -54, -110]
Is it possible to NSLog NSData in base 10. Basically to see byte array of NSData.
I would like to see output something like this: [51, -55, 55, -54, -110]
You can define a category on NSData
to produce a string with decimal data representation, like this:
@interface NSData (DecimalOutput)
-(NSString*)asDecimalString;
@end
@implementation NSData (DecimalOutput)
-(NSString*)asDecimalString {
NSMutableString *res = [NSMutableString string];
[res appendString:@"["];
// Construct an `NSString`, for example by appending decimal representations
// of individual bytes to the output string
const char *p = [self bytes];
NSUInteger len = [self length];
for (NSUInteger i = 0 ; i != len ; i++) {
[res appendFormat:@"%i ", p[i]];
}
[res appendString:@"]"];
return res;
}
@end
Now you can use this to NSLog
strings in the new format:
NSLog("Data:%@", [myData asDecimalString]);