Ken
Ken

Reputation: 31161

Objective-C and scanning an integer or character to a hex representation

NSScanner has the instance method -scanHexInt: for converting a hexadecimal string representation of an int to an int. I'd like to invert this: I'd like a method that takes an int and returns a hexadecimal representation.

Is there a ready made method in the docs?

[To be more relevant, I'd like to take a string comprising a single kanji and return its unicode point.]

Upvotes: 1

Views: 577

Answers (1)

Jim
Jim

Reputation: 73936

If you check the documentation on string format specifiers, you'll see that there are several specifiers you can use to get a hexadecimal string representation of a number. For instance, you could use:

[NSString stringWithFormat:@"%x", foo]

Upvotes: 2

Related Questions