below is my method for Hex to ASCII conversion
-(NSString*)getASCIIString:(NSString*)strHex
{
NSMutableString *strAscii = [NSMutableString string];
for (int i=0;i<24;i+=2) {
NSString *charValue = [strHex substringWithRange:NSMakeRange(i,2)];
unsigned int _byte;
[[NSScanner scannerWithString:charValue] scanHexInt: &_byte];
if (_byte >= 32 && _byte < 127) {
[strAscii appendFormat:@"%c", _byte];
} else {
[strAscii appendFormat:@"[%d]", _byte];
}
}
NSLog(@"Hex: %@", strHex);
NSLog(@"Ascii: %@", strAscii);
return strAscii;
}
Above methode convert Hex String to ASCII but i notice for one scenario giving me wrong result as below:
strHex : 4E4932313533000000000066 Ascii : NI2153[0][0][0][0][0]f (Wrong)
why for 00 i am getting [0]. ?
my method work perfectly fine , only when there is 00 in Hex string as i mentioned i am getting [0] in Ascii string.
Please Let me know tested perfect conversion method.