我正在尝试解码一个protobuff编码的消息,所以我需要将protobuff消息中的第一个字节(密钥)转换成位,这样我就可以找到字段编号.如何将UInt8(字节)转换为位数组?
伪代码
private func findFieldNum(from byte: UInt8) -> Int {
//Byte is 0001 1010
var fieldNumBits = byte[1] ++ byte[2] ++ byte[3] ++ byte[4] //concatentates bits to get 0011
getFieldNum(from: fieldNumBits) //Converts 0011 to field number, 2^1 + 2^0 = 3
}
Run Code Online (Sandbox Code Playgroud)
我看到了这个问题,它将一个位数组转换为字节数组.