How do you read the upper nibble of a status byte?
right_shift moves bits toward less significant positions. Shifting an unsigned byte by four exposes its upper nibble.
numpy.right_shift in practice
Hexadecimal AB has upper nibble A, decimal ten. Signed values can shift in sign bits, so decode protocol bytes using uint8.
import numpy as np
np.right_shift(np.array([0xAB,0x41],dtype=np.uint8),4)Result [10, 4]
中文
如何从状态字节读出高四位?
right_shift 将位向低位移动。对无符号字节右移四位就把高半字节送入低四位。
numpy.right_shift 算例
十六进制 AB 的高半字节为 A,即十进制 10。带符号数可能涉及符号扩展,按协议字节解析时显式使用 uint8。
import numpy as np
np.right_shift(np.array([0xAB,0x41],dtype=np.uint8),4)结果 [10, 4]