Converter seqüência hexadecimal em formato ASCII [duplicado]
Esta pergunta já tem uma resposta aqui:
NSString contendo hex convert para ASCII equivalente 1 respostaEu tenho uma sequência hexadecimal como "000000000100" e estou usando a seguinte lógica para fazer conversão ASCII, a saída que estou recebendo é de apenas 1 byte (\ x01) Mas quero a saída no formato de 6 bytes como \ x00 \ x00 \ x00 \ x00 \ x01 \ x00
-(NSString*) decode
{
string=@"000000000100";
NSMutableString * newString = [[NSMutableString alloc]init];
int i = 0;
while (i < [string length])
{
NSString * hexChar = [string substringWithRange: NSMakeRange(i, 2)];
int value = 0;
sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[newString appendFormat:@"%c", (char)value];
i+=2;
}
return newString;
}
Como fazer isso ?