c or objective-c equivalent of Java's Integer.toHexString()?
Is there is an equivalent in C or Objective-C to do the follo开发者_如何学JAVAwing (taken from Java)
Integer.toHexString(some_int)
For 32 bit Integers:
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/
The printf format specifiers %x and %X allow you to print an integer's hex representation. The same can be used with [NSString stringWithFormat:...] to get an Objective-C string.
精彩评论