Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Signed fixed number - 2s complement

Status
Not open for further replies.

nesta

Junior Member level 2
Joined
Feb 19, 2010
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,466
Hi VhdlExperts,

What is the algorithm to find a 2's complement for a signed fixed point number.

I would like to implement this so would need the algorithm.

eg: 2s complement of (-1.5).

Thanks in Advance.
 

TrickyDicky

Advanced Member level 5
Joined
Jun 7, 2010
Messages
7,025
Helped
2,058
Reputation
4,133
Reaction score
2,010
Trophy points
1,393
Activity points
38,605
fixed point arithmatic is no different to normal arithmatic, so there is no need to "find" a value, and there is no algorithm for it. Its all about where you place the imaginary decimal place. To put a number into fixed point, you just scale it by 2^n.

So -1.5 = -3/2

-3 = 1101 in binary (4 bits)
-1.5 = 110.1 in binary (its just 3 bitshifted by 1 place).

So, if using the singed type, you still declare it with
signal my_number : signed(3 downto 0) := "1101";

But then you need to track the position of the decimal place.

What makes life easier is the new fixed point package in VHDL2008. You can now decalre signals like this:

signal my_number : sfixed(2 downto -1) := "1101";

So here, the first 3 bits (2 downto 0) make up the integer part, and the negative bits (-1) make up the fraction.

It makes tracking fixed point numbers a hell of a lot easier, and reads much better in the code.
 
  • Like
Reactions: ravics

    ravics

    points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top