如何使用NSLog显示十六进制字节

时间:2022-10-13 01:03:05

How can I display the following bytes using NSLog?

如何使用NSLog显示以下字节?

const void *devTokenBytes = [devToken bytes];

2 个解决方案

#1


14  

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.

假设devToken的类型为NSData *(来自字节调用),您可以使用NSData上的description方法获取包含数据字节的十六进制表示的字符串。请参阅NSData类参考。

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

#2


8  

If you want a series of hexes, I used the following:

如果你想要一系列的十六进制,我使用了以下内容:

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

// hex now contains your hex.

#1


14  

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.

假设devToken的类型为NSData *(来自字节调用),您可以使用NSData上的description方法获取包含数据字节的十六进制表示的字符串。请参阅NSData类参考。

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

#2


8  

If you want a series of hexes, I used the following:

如果你想要一系列的十六进制,我使用了以下内容:

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

// hex now contains your hex.