开发者

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

开发者 https://www.devze.com 2023-02-11 16:54 出处:网络
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 a

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]
0

精彩评论

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