0

i have this string

NSString * str = @ "01 00 00 41 8B 00 01 00 00 40 BC 00 01 00 00 43 0D 00";

and i try convert it to NSacii with this finction

- (NSString *)hexToString:(NSString *)string {
    NSMutableString * newString = [[NSMutableString alloc] init];
    NSScanner *scanner = [[NSScanner alloc] initWithString:string];
    unsigned value;
    while([scanner scanHexInt:&value]) {
        [newString appendFormat:@"%c",(char)(value & 0xFF)];
    }
    string = [newString copy];
    [newString release];
    return [string autorelease];
}

it work perfect , but the problem when i want to convert the string to hex i cant find the 00 it mean the result are 01 41 8B 01 40 BC 01 43 0D

Krueger
  • 484
  • 1
  • 5
  • 20
mobileHard
  • 23
  • 5

1 Answers1

0
- (NSString *)hexToString:(NSString *)string {
    NSMutableString * newString = [[NSMutableString alloc] init];
    NSScanner *scanner = [[NSScanner alloc] initWithString:string];
    unsigned value;
    while([scanner scanHexInt:&value]) {
       if (value==0 )
        {

            [newString appendString:@"\0"];

        }
        else
        {
            [newString appendFormat:@"%c",(char)(value & 0xFF)];
        }
    }
    string = [newString copy];
    [newString release];
    return [string autorelease];
}
mobileHard
  • 23
  • 5