How to display hexadecimal bytes using NSLog

前端 未结 2 1452
轮回少年
轮回少年 2021-02-19 20:43

How can I display the following bytes using NSLog?

const void *devTokenBytes = [devToken bytes];
相关标签:
2条回答
  • 2021-02-19 21:14

    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 讨论(0)
  • 2021-02-19 21:18

    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]);
    0 讨论(0)
提交回复
热议问题