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.]
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]
精彩评论