wes. i
wes. i

Reputation: 628

Data type conversion issues

i'm currently trying to save some data in external memory via bluetooth LE. in order to send data i will first convert the string into HEX(ASCII) format

outbuffer += [UInt8](password.utf8)

String -> (HEX)ASCII

but when i retrieve the data back from external memory to get back the original data and i'm doing this

incomingData.getBytes(&array, length: 5)
let originalPassword = UnsafePointer<UInt8>(array).memory

(HEX)ASCII -> String

but i couldn't get back the original data. Can someone suggest me why? i'm new to this data conversion. Thank you

Upvotes: 0

Views: 52

Answers (1)

J.Wang
J.Wang

Reputation: 1236

Try this

String(array.map(UnicodeScalar.init).map(Character.init))

Upvotes: 1

Related Questions