如何计算任意数量的highBytelowByte

范例:

let mValue = 26513


mValue = 0x6791的十六进制表示

那么如何找到上述数字的高低字节呢?

最佳答案

更新迅速:


下面的解决方案为我工作:

    let mVal = 26513 // hex value of mVal = 0x6791 (UInt16)
    let highByte = (mVal >> 8) & 0xff  // hex value of highByte = 0x0067 (UInt8)
    let lowByte = mVal & 0xff // hex value of lowByte = 0x0091 (UInt8)

    print("highByte: \(highByte)\nLowByte: \(lowByte)")

07-26 09:38