美文网首页
Swift3 UInt8 转 Int

Swift3 UInt8 转 Int

作者: ldclll | 来源:发表于2016-11-04 11:23 被阅读496次
    //接收到Data类型的蓝牙数据
    let data = characteristic.value
    
    //将数据转存到[UInt8]数组
    let resultByte = (data?.withUnsafeBytes {
        [UInt8](UnsafeBufferPointer(start: $0, count: (data?.count)!))
        })! as [UInt8]
    
    //以数据长度进行for循环遍历
    for i:Int in 0..<data!.count {
        
        //打印对应的UInt8类型数据
        print("testByte[\(i)] = \(resultByte[i])")
        
        //将UInt8数据转换为Int类型
        let resultData = NSString(format: "%d", resultByte[i]).integerValue
        
        print(resultData)
    }

相关文章

网友评论

      本文标题:Swift3 UInt8 转 Int

      本文链接:https://www.haomeiwen.com/subject/iboiuttx.html