开发者

How to display hexadecimal bytes using NSLog

开发者 https://www.devze.com 2023-01-15 23:03 出处:网络
How can I display the following bytes using NSLog? const void *devTok开发者_如何学运维enBytes = [devToken bytes];

How can I display the following bytes using NSLog?

const void *devTok开发者_如何学运维enBytes = [devToken bytes];


Assuming that devToken is of type NSData * (from the bytes call), you can use the description method on NSData to get a string containing the hexadecimal representation of the data's bytes. See the NSData class reference.

NSLog(@"bytes in hex: %@", [devToken description]);


If you want a hex sequence:

NSMutableString *hex = [NSMutableString stringWithCapacity:[devToken length]];
for (int i=0; i < [devToken length]; i++) {
  [hex appendFormat:@"%02x", [devToken bytes][i]];
}
0

精彩评论

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