max_
max_

Reputation: 24521

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.

Upvotes: 1

Views: 4870

Answers (1)

Anomie
Anomie

Reputation: 94844

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).

Upvotes: 3

Related Questions