How to convert hexadecimal string to decimal?
I would appreciate it if you could tell me how I can convert hexadecimal letters within an NSString
, e.g. @"50A6C2"
, to decimals using Objective-C. Thanks in advance.开发者_运维技巧
The easiest way is to use an NSScanner, specifically the methods scanHexInt:
or scanHexLongLong:
. Another possibility is to get the C string from the NSString and use C-style functions such as strtol
(with base 16).
精彩评论