开发者

c or objective-c equivalent of Java's Integer.toHexString()?

开发者 https://www.devze.com 2023-03-12 09:51 出处:网络
Is there is an equivalent in C or Objective-C to do the follo开发者_如何学JAVAwing (taken from Java)

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.

0

精彩评论

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

关注公众号