fixed point representation and signed numbers

B

blackpadme

Hi, i'm working with fixed point numbers which have two bits for no-
fractional part (in two complement) and eight bits for fractional
(i.e. pi/2 = 0.5703 => 00.10010010). But, what happen if i need
signed representation for the fractional part ? 11.10010010 = -1.5703.
What can i do if a need to represent -pi/2 and i need to work across
division, add, multiplicacion etc. ?

Thanks.
 
R

rickman

It would be very unusual to have both the integer part and
the fractional part represented as 2s complement. It makes much
more sense to keep the usual fixed-point representation in which
the fraction is invariably unsigned:

10.00000000 -2 + .00 = -2.00
10.01000000 -2 + .25 = -1.75
10.10000000 -2 + .50 = -1.5
10.11000000 -2 + .75 = -1.25
11.00000000 -1 + .00 = -1.00
11.01000000 -1 + .25 = -0.75
11.10000000 -1 + .50 = -0.5
11.11000000 -1 + .75 = -0.25
00.00000000 0 + .00 = 0.00

You can then treat the whole 10-bit fixed-point number as if
it were a regular 2s complement integer, except that it is
scaled by 1/256.

I don't understand what you are saying. Or maybe you are just using
some sort of a mnemonic for 2's complement. But what you have written
above is no different than just treating the entire number as a 2's
complement value...

Or are you just messing with our heads?

Rick
 
R

rickman

It would be very unusual to have both the integer part and
the fractional part represented as 2s complement. It makes much
more sense to keep the usual fixed-point representation in which
the fraction is invariably unsigned:

10.00000000 -2 + .00 = -2.00
10.01000000 -2 + .25 = -1.75
10.10000000 -2 + .50 = -1.5
10.11000000 -2 + .75 = -1.25
11.00000000 -1 + .00 = -1.00
11.01000000 -1 + .25 = -0.75
11.10000000 -1 + .50 = -0.5
11.11000000 -1 + .75 = -0.25
00.00000000 0 + .00 = 0.00

You can then treat the whole 10-bit fixed-point number as if
it were a regular 2s complement integer, except that it is
scaled by 1/256.

I don't understand what you are saying. Or maybe you are just using
some sort of a mnemonic for 2's complement. But what you have written
above is no different than just treating the entire number as a 2's
complement value...

Or are you just messing with our heads?

Rick
 
R

rickman

Precisely.  The OP was asking about using a signed
representation for the *fraction* as well as the integer
part of a fixed-point number, and I was trying to show
why that doesn't make a lot of sense.


Not intentionally.  I'm a little hard-pressed
to understand why my attempt to enumerate
a few values in conventional 2.8 fixed-point
signed representation is upsetting you so :)

The problem is that you seem to be saying that there is nothing
different about fixed point integer vs. fraction and yet, you describe
the integer as signed and the fraction as not. I can describe
integers in the exact same terms you are describing fixed point by
talking about the integer part above 8 and the integer part below 8.
It is just simple math...

10 11 = -8 + (2 + 1) = 5
|| ||_ 1
|| |__ 2
||
||____ no 4
|_____ 8

The way you are looking at it, the separation really is not at the
fixed point, it is at the ***sign bit*** -2**(n-1) + ...

The definition of 2's comp of k is 2**n - k. You talk about
interpreting the bits with odd weights, i.e. -2**(n-1) * bit (n-1)
instead. Yes, this works, but this is not the definition of 2's
complement.

1011 = -16 + 8 + 2 + 1 = 5
||||_ 1
|||__ 2
||___ no 4
|____ 8

By using this altered notation, you make the integer and fraction
*appear* different.

10.11 = -2 + 0.5 + 0.25 = -1.25 = -5/4
|| ||_ .25
|| |__ .5
||____ no 1
|_____ 2

or

10.11 = -4 + 2 + (0.5 + 0.25) = -1.25
|| ||_ .25
|| |__ .5
||____ no 1
|_____ 2

Notice that I treat *all* the bits as positive values to be added to
the -2**n value. So the full number is a ***single*** 2's complement
entity. It makes no *sense* to talk about the integer and fraction as
separate notations.

Obviously we are saying the same conclusion, that there is no need to
introduce any special handling of the fraction vs. the integer. But
in the explanation of this conclusion, you *do* exactly that, treat
the integer and fraction differently!

Rick
 
R

rickman

Precisely.  The OP was asking about using a signed
representation for the *fraction* as well as the integer
part of a fixed-point number, and I was trying to show
why that doesn't make a lot of sense.


Not intentionally.  I'm a little hard-pressed
to understand why my attempt to enumerate
a few values in conventional 2.8 fixed-point
signed representation is upsetting you so :)

The problem is that you seem to be saying that there is nothing
different about fixed point integer vs. fraction and yet, you describe
the integer as signed and the fraction as not. I can describe
integers in the exact same terms you are describing fixed point by
talking about the integer part above 8 and the integer part below 8.
It is just simple math...

10 11 = -8 + (2 + 1) = 5
|| ||_ 1
|| |__ 2
||
||____ no 4
|_____ 8

The way you are looking at it, the separation really is not at the
fixed point, it is at the ***sign bit*** -2**(n-1) + ...

The definition of 2's comp of k is 2**n - k. You talk about
interpreting the bits with odd weights, i.e. -2**(n-1) * bit (n-1)
instead. Yes, this works, but this is not the definition of 2's
complement.

1011 = -16 + 8 + 2 + 1 = 5
||||_ 1
|||__ 2
||___ no 4
|____ 8

By using this altered notation, you make the integer and fraction
*appear* different.

10.11 = -2 + 0.5 + 0.25 = -1.25 = -5/4
|| ||_ .25
|| |__ .5
||____ no 1
|_____ 2

or

10.11 = -4 + 2 + (0.5 + 0.25) = -1.25
|| ||_ .25
|| |__ .5
||____ no 1
|_____ 2

Notice that I treat *all* the bits as positive values to be added to
the -2**n value. So the full number is a ***single*** 2's complement
entity. It makes no *sense* to talk about the integer and fraction as
separate notations.

Obviously we are saying the same conclusion, that there is no need to
introduce any special handling of the fraction vs. the integer. But
in the explanation of this conclusion, you *do* exactly that, treat
the integer and fraction differently!

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top