iOS進数変換

498 ワード

1、C言語関数を使う

//strtoul(const char *__str, char **__endptr, int __base);
//    (        )
NSUInteger val = strtoul([[@"586de4e0" substringWithRange:NSMakeRange(0, 10)] UTF8String], 0, 10);

2、使用出力
NSTimeInterval time = [[NSDate date]timeIntervalSince1970];

//        
NSString *valStr = [NSString stringWithFormat:@"%lx",(unsigned long)time];

//       
NSString *valStr = [NSString stringWithFormat:@"%lo",(unsigned long)time];