byte和Data之间的转换
var b:[Byte] = [13,0xf1,0x20]
var d = NSData(bytes: b, length: 3)
//把NSData的值存到byteArray中
var byteArray:[Byte] = [Byte]()
for i in 0..<3 {
var temp:Byte = 0
d.getBytes(&temp, range: NSRange(location: i,length:1 ))
byteArray.append(temp)
}
四个字节的byte转整形数据
/** 4个字节Bytes 转 int*/
unsigned int bytesValueToInt(Byte *bytesValue) {
unsigned int intV;
intV = (unsigned int ) ( ((bytesValue[3] & 0xff)<<24)
|((bytesValue[2] & 0xff)<<16)
|((bytesValue[1] & 0xff)<<8)
|(bytesValue[0] & 0xff));
return intV;
}
网友评论