Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

q notation for verilog

Status
Not open for further replies.

arunshanmugam46

Junior Member level 2
Joined
Jan 8, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,422
how to represent a floating point -3.3456 using q format .....

---------- Post added at 16:19 ---------- Previous post was at 16:18 ----------

note: using Q1.6 format (1bit-integer,1bit-sign 6bit-fractional part)
 

i am aware of q notation.....my doubt is how to add two Q1.6 format numbers eg:-0.8364 and -0.9127 ........
when i use 2's complement addition am getting a wrong value.......
 

To get the 2-complement bit pattern for negative values, add the integer range size for the format.
That is the integer close to (max value) - (min value).
For Q1.6 this is 2 - (-2) = 4.

-0.8364 + 4 = 3.1636, which is the Q1.6 2-complement value of -0.8364 with sign => 11.001010
-0.9127 + 4 = 3.0873, which is the Q1.6 2-complement value of -0.9127 with sign => 11.000110

Add and discard the "overflow" bit:

11.001010
11.000110
=========
10.010000

The highest bit is the sign bit. It is set so the number is negative. Subtract 4 to get the decimal number:
2.25 - 4 = -1.75

Check: (-0.8364) + (-0.9127) = -1.7491
 

To get the 2-complement bit pattern for negative values, add the integer range size for the format.
That is the integer close to (max value) - (min value).
For Q1.6 this is 2 - (-2) = 4.

-0.8364 + 4 = 3.1636, which is the Q1.6 2-complement value of -0.8364 with sign => 11.001010
-0.9127 + 4 = 3.0873, which is the Q1.6 2-complement value of -0.9127 with sign => 11.000110

Add and discard the "overflow" bit:

11.001010
11.000110
=========
10.010000

The highest bit is the sign bit. It is set so the number is negative. Subtract 4 to get the decimal number:
2.25 - 4 = -1.75

Check: (-0.8364) + (-0.9127) = -1.7491
-0.9127 + 4 = 3.0873, which is the Q1.6 2-complement value of -0.9127 is 11.000101 not 11.000110
 

-0.9127 + 4 = 3.0873, which is the Q1.6 2-complement value of -0.9127 is 11.000101 not 11.000110
If a number can't be expressed exactly in a given format, why are you truncating instead of rounding to the nearest value?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top