在Swift iOS中计算高字节和低字节?

时间:2019-07-15 07:49:38

标签: ios swift bluetooth-lowenergy byte

如何计算任意数量的highBytelowByte

示例:

let mValue = 26513

mValue = 0x6791的十六进制表示形式

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

1 个答案:

答案 0 :(得分:0)

  

已迅速更新:

以下解决方案对我有用:

    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)")
相关问题