0

I have to send a byte array of hexadecimal integers to a BLE devise. Whenever I try to use 0x notation the internal value stored in the byte array is getting converted to a decimal value.

var foo : [Byte] = [0xff, 0xD9] is actually stored as [255, 217]

What data structure should I be using to make it stay in hex format ?

1 Answer 1

1

You keep bytes in a byte array and what do they mean is up for your interpretation. So what you are keeping there are bytes of value 255 and 217 in base10 and 0xFF and 0xD9 in base16. They are actually kept as 1111 1111 and 1101 1001 in base2. (Computer number format)

You can safely send your byte array without any changes.

If you want to print out your bytes in hexadecimal you can go with something like this:

println (foo.map { String($0, radix: 16, uppercase: false) })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.