ios - 在swift iOS中计算高字节和低字节?

标签 ios swift bluetooth-lowenergy byte

如何计算任意数字的highBytelowByte

示例:

let mValue = 26513

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

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

最佳答案

Updated for swift :

以下解决方案对我有用:

    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)")

关于ios - 在swift iOS中计算高字节和低字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57035368/

相关文章:

ios - 自定义 Segue 后退按钮使应用程序崩溃

ios - IOS 的应用程序内可以接收短信通知吗?

ios - 为什么 invalidateLayout 不触发 UICollectionView 中的 sizeForItemAtIndexPath? (附代码)

ios - 我可以将 Crashlytics 添加到 iOS 库吗?

ios - Swift:点击 UITextField 时如何显示 UIPickerView

ios - IBDesignable 在添加到 UIStackView 时不起作用

ios - 在 iOS 中以后台模式将数据从 Central 传输到外围设备

iOS 8 无法连接到 BLE。可以连接到 iOS 9

android - 蓝牙Gatt : onClientConnectionState() returns status=133

iOS UIWebView 只显示黑色背景