ΣSigmaStudio Ask AI Русский Log in

Divide an integer by 3

SigmaDSP & SigmaStudio op-electronics Nov 24, 2016 00:00 2 replies Original on forum ↗
Subscribe
op-electronics Question
Nov 24, 2016 00:00

How to perform division by 3 of an integer number in SigmaStudio?

Thank you in advance!

Omar

integer divide

KJBob Reply
Nov 25, 2016 00:00

Hello Omar,

The most economical way to divide by a constant number (such as 3) is to multiply by its reciprocal. An example running on the ADAU1701 is shown below.

Here the input integer is 27. To divide by 3, we can multiply by 0.3334. Because the multiplication only rounds down, increasing the last digit of the multiplier by one helps provide a correct result. The ADAU1701's readback register is only 24 bits wide, truncating the lowest 4 bits -- thus we need to shift 4 bits to the left (multiply by 16) to correctly readback an integer number.

Best regards,

Bob

d4af9915dfadfd1f5c485517820581bb.png
d4af9915dfadfd1f5c485517820581bb.png
d4af9915dfadfd1f5c485517820581bb.png-506x230.png
d4af9915dfadfd1f5c485517820581bb.png-506x230.png
op-electronics Reply
Nov 25, 2016 00:00

Embarassing how simple it was.

Thanks Bob!