fixed point representation and signed numbers

Discussion in 'VHDL' started by blackpadme, Sep 5, 2008.

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

Thanks.

2. rickmanGuest

On Sep 5, 11:23 am, Jonathan Bromley <>
wrote:
> On Fri, 5 Sep 2008 07:50:48 -0700 (PDT), blackpadme wrote:
> >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. ?

>
> 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

rickman, Sep 6, 2008

3. rickmanGuest

On Sep 5, 11:23 am, Jonathan Bromley <>
wrote:
> On Fri, 5 Sep 2008 07:50:48 -0700 (PDT), blackpadme wrote:
> >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. ?

>
> 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

rickman, Sep 6, 2008
4. rickmanGuest

On Sep 7, 4:46 am, Jonathan Bromley <>
wrote:
> On Sat, 6 Sep 2008 15:59:01 -0700 (PDT), rickman <>
> wrote:
>
> > what you have written above is no different
> > than just treating the entire number as a 2's
> > complement value...

>
> 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.
>
> > Or are you just messing with our heads?

>
> 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

> Perhaps this Number Representations 101
> express my intent more clearly, at least
> if you view it with a monospaced font:
>
> Ordinary binary integers work like this
> (using a 4-bit example)
>
>    1011       = 8 + 2 + 1 = 11
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ 8
>
> Twos complement works by making the most significant
> bit have the same value it would usually have, but
> negated:
>
>    1011       = -8 + 2 + 1 = -5
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ -8
>
>    0011       = 2 + 1 = 3
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ no -8
>
> In particular, note that every bit EXCEPT the MSB
> works in exactly the same way as it did for straight
> binary; the only difference is that the MSB is negative.
>
> Now let's move to fixed-point, using 2 integer and
> 2 fraction bits for the example.  Basically it's
> just an integer scaled by 1/4:
>
>    1011       = 2 + 0.5 + 0.25 = 2.75 = 11/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ 2
>
> And in twos complement, it's exactly the same
> except that the MSB is negative:
>
>    1011       = -2 + 0.5 + 0.25 = -1.25 = -5/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ -2
>
>    0011       = 0.5 + 0.25 = 0.75 = 3/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ no -2
>
> The fraction bits remain positive; there is no
> need to introduce a special signed representation
> for the fraction.  As rickman said, it's precisely
> a twos-complement integer - except you think of it
> as being right-shifted by the number of fraction bits.

rickman, Sep 7, 2008
5. rickmanGuest

On Sep 7, 4:46 am, Jonathan Bromley <>
wrote:
> On Sat, 6 Sep 2008 15:59:01 -0700 (PDT), rickman <>
> wrote:
>
> > what you have written above is no different
> > than just treating the entire number as a 2's
> > complement value...

>
> 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.
>
> > Or are you just messing with our heads?

>
> 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

> Perhaps this Number Representations 101
> express my intent more clearly, at least
> if you view it with a monospaced font:
>
> Ordinary binary integers work like this
> (using a 4-bit example)
>
>    1011       = 8 + 2 + 1 = 11
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ 8
>
> Twos complement works by making the most significant
> bit have the same value it would usually have, but
> negated:
>
>    1011       = -8 + 2 + 1 = -5
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ -8
>
>    0011       = 2 + 1 = 3
>    ||||_ 1
>    |||__ 2
>    ||___ no 4
>    |____ no -8
>
> In particular, note that every bit EXCEPT the MSB
> works in exactly the same way as it did for straight
> binary; the only difference is that the MSB is negative.
>
> Now let's move to fixed-point, using 2 integer and
> 2 fraction bits for the example.  Basically it's
> just an integer scaled by 1/4:
>
>    1011       = 2 + 0.5 + 0.25 = 2.75 = 11/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ 2
>
> And in twos complement, it's exactly the same
> except that the MSB is negative:
>
>    1011       = -2 + 0.5 + 0.25 = -1.25 = -5/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ -2
>
>    0011       = 0.5 + 0.25 = 0.75 = 3/4
>    ||||_ 0.25
>    |||__ 0.50
>    ||___ no 1
>    |____ no -2
>
> The fraction bits remain positive; there is no
> need to introduce a special signed representation
> for the fraction.  As rickman said, it's precisely
> a twos-complement integer - except you think of it
> as being right-shifted by the number of fraction bits.

rickman, Sep 7, 2008