Using decimal numbers, 0x400 is 1024, and 1024 times 2^15 is, 1024 * 32768 = 33554432. If you convert this back to hexadecimal, then you get 0x2000000.

Using shifts, 0x400 << 12 is 0x400 with another 3 zeros on the right (12/4 is 3), or 0x400000. This has to be shifted left another three places (15-12 is 3). One shift results in 0x800000, two shifts 0x1000000 and finally the third shift is 0x2000000.

How are you doing the calculations?

Cheers,

Shawn

0x400 << 15 = 80000000 not 0x02000000. How did you get the anwer then?

]]>I want to know how to perform MAC calculations using Q-format numbers. ]]>

Thanks,

Shawn

I’m working on FIR implementation using Distributed Arithmetic. And I have to use Q format numbers for MAC calculations. I understood the concept of Q format number but getting confused about using them in calculations. Can you please help me?

Thanks. ]]>

I’m glad the article is useful for you. When the dividend is greater than the divisor, you need to know how much bigger it will be, or use a lot more bits in your result. For example, if you know that the magnitude of the dividend is no larger than one, and the magnitude of the divisor can be as small as 0.5, then the largest magnitude of the result would be 2. You could shift your result such that a value this large could be represented. If you had no restrictions, then you might need to keep a lot of bits in the result to represent the entire range of possible results. In my last example, the division of two Q15 numbers would require a Q30 number to hold the range of results possible.

The multiplication by reciprocal that I mentioned was to do with constant values. I think most C/C++ compilers these days would automatically change a division by constant to a multiplication automatically when optimization is done. I was probably thinking back to when I used to write things in assembly code. I wouldn’t recommend doing a reciprocal normally, unless the result is going to be multiplied by more than one different value afterwards.

I hope that helps.

Shawn

I am struggling to get the division in case of [dividened>divisor], whose result is greater than one.

Would you have any ideas to solve this?

Also, in the beginning of this blog, you mentioned it should be better to multiply by the reciprocal than to do a division.

I wonder how your solution would be to get the reciprocal. might do it by Newton-method? ]]>

The important thing is to know the range of the coefficients, and how many bits will be needed to represent your range of numbers in fixed point. If you don’t use enough bits, then your smallest coefficients may end up as zeroes. When going from double to fixed point, you can round the coefficients to an integer value before casting to an integer. In many cases, it won’t matter how you round or truncate, because the least significant bits are not that significant compared to the magnitude of the coefficient. What in particular did you want to know about the transformation process?

Thanks,

Shawn