普通字符串转换为十六进制

//普通字符串转换为十六进制的。
-(NSString *)ToHex:(long long int)tmpid
{
    //    NSString *endtmp=@"";
    NSString *nLetterValue;
    //    NSString *nStrat;
    NSString *str =@"";
    //    tmpid = 13621631651;
    long long int ttmpig;


    for (int i = 0; i<9; i++) {
       
        ttmpig=tmpid%16;
        tmpid=tmpid/16;
        switch (ttmpig)
        {
            case 10:
                nLetterValue =@"A";break;
            case 11:
                nLetterValue =@"B";break;
            case 12:
                nLetterValue =@"C";break;
            case 13:
                nLetterValue =@"D";break;
            case 14:
                nLetterValue =@"E";break;
            case 15:
                nLetterValue =@"F";break;
            default:nLetterValue=[[[NSString alloc]initWithFormat:@"%i",ttmpig] autorelease];
        }
        str = [nLetterValue stringByAppendingString:str];
        if (tmpid == 0) {
            break;
        }
    }
    //        } while (tmpid == 0);
    //
    return str;
}

你可能感兴趣的:(ios)