DSPRelated.com
Forums

6.3121 in fixed point?

Started by Luis Fernando October 29, 2004
hello

i'm working with a motorola that can represent 1.15 fixed-point numbers

any ideas on how can I multiply a number by 6.3121?

thanks
On 29 Oct 2004 07:47:13 -0700, wavebox@wavebox.com.br (Luis
Fernando) wrote:

>>i'm working with a motorola that can represent 1.15 fixed-point numbers >> >>any ideas on how can I multiply a number by 6.3121?
6.3121 = 4 + 2 + 0.3121 Multiply by 4 = left shift twice Multiply by 2 = left shift once 0.3121 = 0x4FE6 in 1.15 fixed or Multiply by 0.7890125, then left-shift three times
Bank-to-Turn <Bank-to-Turn@mchsi.com> writes:

> On 29 Oct 2004 07:47:13 -0700, wavebox@wavebox.com.br (Luis > Fernando) wrote: > > >>i'm working with a motorola that can represent 1.15 fixed-point numbers > >> > >>any ideas on how can I multiply a number by 6.3121? > > 6.3121 = 4 + 2 + 0.3121 > > Multiply by 4 = left shift twice > > Multiply by 2 = left shift once > > 0.3121 = 0x4FE6 in 1.15 fixed > > or > > Multiply by 0.7890125, then left-shift three times
Teach a man to fish... -- Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 919-472-1124
On Fri, 29 Oct 2004 19:14:25 GMT, Bank-to-Turn
<Bank-to-Turn@mchsi.com> wrote:

>> 0.3121 = 0x4FE6 in 1.15 fixed
Should be 0x27F3
Luis Fernando wrote:
> hello > > i'm working with a motorola that can represent 1.15 fixed-point numbers > > any ideas on how can I multiply a number by 6.3121? > > thanks
I'm not sure what you mean by 1.15. I assume this means 1 bit left of the radix point and 15 bits right of the radix point, although you obviously can't store '6' in one bit. But if we assume three bits of integer and 15 bits of fraction, 6.3121 = 110.010011111110011 I used a function I wrote for Matlab to do this, but you can do the same thing manually: integer part (6) = 110 fraction part (.3121) * 2^15 = 010011111110011 -Kevin

Kevin Neilson wrote:

> Luis Fernando wrote:
>> i'm working with a motorola that can represent 1.15 fixed-point numbers
>> any ideas on how can I multiply a number by 6.3121?
> I'm not sure what you mean by 1.15. I assume this means 1 bit left of > the radix point and 15 bits right of the radix point, although you > obviously can't store '6' in one bit. But if we assume three bits of > integer and 15 bits of fraction,
He wants to multiply a 1.15 number by decimal 6.13121. The product could have more than one bit to the left of the binary point, but he can either keep it (not in 1.15) or truncate it. I don't know how the motorola multiply works, but in most cases it can be done with some pre or post shifting. -- glen
glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

> Kevin Neilson wrote: > >> Luis Fernando wrote: > >>> i'm working with a motorola that can represent 1.15 fixed-point numbers > >>> any ideas on how can I multiply a number by 6.3121? > >> I'm not sure what you mean by 1.15. I assume this means 1 bit left >> of the radix point and 15 bits right of the radix point, although >> you obviously can't store '6' in one bit. But if we assume three >> bits of integer and 15 bits of fraction, > > He wants to multiply a 1.15 number by decimal 6.13121. The product > could have more than one bit to the left of the binary point, but > he can either keep it (not in 1.15) or truncate it. > > I don't know how the motorola multiply works, but in most cases > it can be done with some pre or post shifting.
The OP should note that whether the number is 1.15, 16.0, or whatever, the difference is chiefly in your viewpoint. What Motorola hardware does is left shift by one after a multiply, which allows two numbers that were originally in fractional format (1.15) to remain in fractional format. However, those numbers don't HAVE to be considered fractional. -- % Randy Yates % "Ticket to the moon, flight leaves here today %% Fuquay-Varina, NC % from Satellite 2" %%% 919-577-9882 % 'Ticket To The Moon' %%%% <yates@ieee.org> % *Time*, Electric Light Orchestra http://home.earthlink.net/~yatescr
Randy Yates wrote:

(snip)

> The OP should note that whether the number is 1.15, 16.0, or whatever, > the difference is chiefly in your viewpoint. What Motorola hardware > does is left shift by one after a multiply, which allows two numbers that > were originally in fractional format (1.15) to remain in fractional format. > However, those numbers don't HAVE to be considered fractional.
Many (non-DSP) processors provide a multiply instruction that will multiply two N bit numbers producing an 2N bit product. The position of the binary point in the operands determine the position in the product. A shift will put the appropriate bits into the destination register. -- glen
glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

> Randy Yates wrote: > > (snip) > >> The OP should note that whether the number is 1.15, 16.0, or whatever, >> the difference is chiefly in your viewpoint. What Motorola hardware >> does is left shift by one after a multiply, which allows two numbers that >> were originally in fractional format (1.15) to remain in fractional >> format. However, those numbers don't HAVE to be considered >> fractional. > > Many (non-DSP) processors provide a multiply instruction > that will multiply two N bit numbers producing an 2N bit product. > The position of the binary point in the operands
... which is the viewpoint I speak of (you won't actually SEE a decimal place in the debugger when you examine the operands - it is implied by usage) ...
> determine the position in the product. A shift will put the > appropriate bits into the destination register.
It might be a little more precise to say "a shift will place the implied binary point at the desired location." We've gone over this here a few dozen times in past years, but for the OP's sake, here's a quick explanation. Let's generalize the binary point location and say that we have two operands in x.y format. When we multiply them, the result is in 2x.2y format. In order to "left-justify" the binary point so that the result is x.(2y + x) (i.e., to match the input binary point), we shift left by x bits. If the inputs are considered fractional numbers (-1 <= N < +1), then x = 1 and the amount of left shift required is 1. FYI, I do not like using this notation. An "x.y" number implies you have x bits for the integer portion of the number, and you do not (you have x-1 bits). -- % Randy Yates % "I met someone who looks alot like you, %% Fuquay-Varina, NC % she does the things you do, %%% 919-577-9882 % but she is an IBM." %%%% <yates@ieee.org> % 'Yours Truly, 2095', *Time*, ELO http://home.earthlink.net/~yatescr

Randy Yates wrote:

(snip)

> We've gone over this here a few dozen times in past years, but for the > OP's sake, here's a quick explanation. Let's generalize the binary > point location and say that we have two operands in x.y format. When > we multiply them, the result is in 2x.2y format. In order to > "left-justify" the binary point so that the result is x.(2y + x) > (i.e., to match the input binary point), we shift left by x bits. If > the inputs are considered fractional numbers (-1 <= N < +1), then x = > 1 and the amount of left shift required is 1.
To generalize a little more, if you multiply v.w by x.y the product has the form v+x.w+y. You then need to shift to get the appropriate bits of the product, which could have p.q format, into the appropriate register bits.
> FYI, I do not like using this notation. An "x.y" number implies you > have x bits for the integer portion of the number, and you do not (you > have x-1 bits).
Well, I would say that you should subtract 1 for signed numbers before writing them that way. Note that PL/I, one of the few languages that support such operations, expresses it as the number of value bits, not including the sign bit, comma, the number after the radix point. That is, FIXED BINARY(15,15) for 15 bits, not counting sign, and 15 after the binary point. PL/I will also do FIXED DECIMAL with the decimal point in various places. -- glen