// 将int转化为UInt8
@objc class func toUint(signed: Int) -> UInt {
let unsigned = signed >= 0 ?
UInt(signed) :
UInt(signed - Int.min) + UInt(Int.max) + 1
return unsigned
}
// 将UInt8 转化为 int
func convertToInt(unsigned: UInt) -> Int {
let signed = (unsigned <= UInt(Int.max)) ?
Int(unsigned) :
Int(unsigned - UInt(Int.max) - 1) + Int.min
return signed
}
网友评论