求助:如何较精确地实现负数的右移位操作
不知哪位能帮忙解答一下,多谢了!
I just present my ideas, any other opinion, Pls discuss.
First, you must know the format of your operator, just to say, the amount of the integer and the fraction. The 4bit 1111, we can reckon it whole as integer.
Second, you have to pay attention to saturation and return-to-zero. Left shifter need saturation and right shifter need return-2-zero.
Third, Symbol-bit do not join shifting.
Your 1111 should be zero after shifting, so just define it as 0000. Before shifting, you should judge if the operator would beyond zero or under under zero after shifting. If the expected result will be under threshold, just force it to a constant.
For example, 1100 is -4, to shift right for two bits, it should be 1111, -1.
不要把这个问题想的太复杂,负数的移位中,对-1做一个专门的判断就行了。