i have following code converting hex value corresponding nsstring not working me
nsmutablestring * newstring = [[nsmutablestring alloc] init]; nsstring *string=@"5c 57 c7 25 d9 57 b9 4c"; nsscanner *scanner = [[nsscanner alloc] initwithstring:string]; unsigned value; while([scanner scanhexint:&value]) { [newstring appendformat:@"%c",(char)(value & 0xff)]; } string = [newstring copy]; nslog(@"%@",string);
please me
once try this,
- (nsstring *) stringfromhex:(nsstring *)str { nsmutabledata *stringdata = [[nsmutabledata alloc] init] ; unsigned char whole_byte; char byte_chars[3] = {'\0','\0','\0'}; int i; (i=0; < [str length] / 2; i++) { byte_chars[0] = [str characteratindex:i*2]; byte_chars[1] = [str characteratindex:i*2+1]; whole_byte = strtol(byte_chars, null, 16); [stringdata appendbytes:&whole_byte length:1]; } return [[nsstring alloc] initwithdata:stringdata encoding:nsasciistringencoding] ; }
call ,
nsstring* string = [self stringfromhex:@"5c 57 c7 25 d9 57 b9 4c"]; nslog(@"%@",string);
Comments
Post a Comment