i have an UInt8 array that contains values between 0 and 255
i would like to convert this array to Int8 array in order to contains values between -128 and 127
How to achieve this in swift?
使用map
和适当的初始化程序:
let intArray = uintArray.map { Int8(bitPattern: $0) }
You can convert a [UInt8] to a [Int8] by using this:
for el in uint8Array {
uint8Array.append(UInt8(bitPattern: el))
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.