在 swift iOS 中计算高字节和低字节



如何计算任何数字的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)")

最新更新