2

After searching for a while, I can't figure out how to get this simple result:

let byte : UInt8 = 0xF3 //Should become "F3"

I have tried this method that won't compile when passing-in either a byte or a byte array.

5

1 Answer 1

3

Two ways:

let s1 = String(byte, radix: 16, uppercase: true) // does not do 0-padding but works with
                                                  // all radices between 2 and 36

let s2 = String(format: "%02X", byte)             // very similar to C
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for clarifying, I can't believe such a response did not exist yet!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.