开发者

hexadecimal to nsuinteger cocoa

How can i convert a Hexadecimal nu开发者_Python百科mber to a nsuinteger


You can use NSScanner if your hex number is in an NSString:

NSScanner* scanner = [NSScanner scannerWithString:@"0xFF"];
unsigned int foo;
[scanner scanHexInt:&foo];
NSLog(@"Integer: %ld",foo);
scanner = [NSScanner scannerWithString:@"FF"];
[scanner scanHexInt:&foo];
NSLog(@"Integer: %ld",foo);

Admittedly, this doesn't scan directly to an NSUInteger, you'd need to cast the result, but it should be enough for your purposes.


strtoul(s, NULL, 16);


Here's one solution which uses the libc function sscanf(),

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜