[英]c or objective-c equivalent of Java's Integer.toHexString()?
Is there is an equivalent in C or Objective-C to do the following (taken from Java) C 或 Objective-C 中是否有等效项来执行以下操作(取自 Java)
Integer.toHexString(some_int)
For 32 bit Integers:对于 32 位整数:
char buffer[enough_space_for_the_largest_string..];
sprintf (buffer, "%08x", YourNumber);
NSString *hexString = [NSString stringWithFormat:@"%x", yourNumber];
You can use itoa()
with a base of 16 http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/您可以使用以 16 为基数的
itoa()
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/
The printf format specifiers %x and %X allow you to print an integer's hex representation. printf 格式说明符 %x 和 %X 允许您打印整数的十六进制表示。 The same can be used with [NSString stringWithFormat:...] to get an Objective-C string.
同样可以与 [NSString stringWithFormat:...] 一起使用以获取 Objective-C 字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.