首页 > 代码库 > iOS 对两个相等长度的字符串进行异或运算

iOS 对两个相等长度的字符串进行异或运算

+ (NSString *)pinxCreator:(NSString *)pan withPinv:(NSString *)pinv{    if (pan.length != pinv.length)    {        return nil;    }        const char *panchar = [pan UTF8String];    const char *pinvchar = [pinv UTF8String];            NSString *temp = [[NSString alloc] init];    for (int i = 0; i < pan.length; i++)    {        int panValue =http://www.mamicode.com/ [self charToint:panchar[i]];        int pinvValue =http://www.mamicode.com/ [self charToint:pinvchar[i]];                temp = [temp stringByAppendingString:[NSString stringWithFormat:@"%X",panValue^pinvValue]];    }    return temp;    }+ (int)charToint:(char)tempChar{    if (tempChar >= 0 && tempChar <=9)    {        return tempChar - 0;    }    else if (tempChar >= A && tempChar <= F)    {        return tempChar - A + 10;    }        return 0;}

 

测试数据

    pan = @"0000001045670006";

    pinv= @"06123456FFFFFFFF";

 

iOS 对两个相等长度的字符串进行异或运算