Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 632 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I convert my device token (NSData) into an NSString?

#21
Explanation of `%02.2hhx` in the high vote [answer](

[To see links please register here]

):

- `%`: Introduces the `x` conversion specifier.
- `02`: The minimum width of the converted value is 2. If the converted value has fewer bytes than the field width, it shall be padded with `0` on the left.
- `.2`: Gives the minimum number of digits to appear for the `x` conversion specifier.
- `hh`: Specifies that the `x` conversion specifier applies to a signed char or unsigned char argument (the argument will have been promoted according to the integer promotions, but its value shall be converted to signed char or unsigned char before printing).
- `x`: The unsigned argument shall be converted to unsigned hexadecimal format in the style "dddd"; the letters "abcdef" are used. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it shall be expanded with leading zeros. The default precision is 1. The result of converting zero with an explicit precision of zero shall be no characters.

For more details, see the [IEEE printf specification](

[To see links please register here]

).

---

Based on the above explanation, I think it is better to change `%02.2hhx` to `%02x` or `%.2x`.

For Swift 5, the following methods are all feasible:

```
deviceToken.map({String(format: "%02x", $0)}).joined()
```

```
deviceToken.map({String(format: "%.2x", $0)}).joined()
```

```
deviceToken.reduce("", {$0 + String(format: "%02x", $1)})
```

```
deviceToken.reduce("", {$0 + String(format: "%.2x", $1)})
```

The test is as follows:
```
let deviceToken = (0..<32).reduce(Data(), {$0 + [$1]})
print(deviceToken.reduce("", {$0 + String(format: "%.2x", $1)}))
// Print content:
// 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through