微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 求助:如何较精确地实现负数的右移位操作

求助:如何较精确地实现负数的右移位操作

时间:10-02 整理:3721RD 点击:
如 :-1用4bit补码表示为1111,-1右移2位之后应该为0,但是1111右移2位之后确还是-1,而且不管右移几位都还是-1
不知哪位能帮忙解答一下,多谢了!

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做一个专门的判断就行了。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top