开发者

hexadecimal to nsuinteger cocoa

开发者 https://www.devze.com 2022-12-21 11:40 出处:网络
How can i convert a Hexadecimal nu开发者_Python百科mber to a nsuintegerYou can use NSScanner if your hex number is in an NSString:

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

精彩评论

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

关注公众号