Forum Discussion
Altera_Forum
Honored Contributor
11 years agoDividing numbers by constants without dividers?
Hi! I would like to divide a number by a set of constants (3, 5 or 7) and I have read in an old post that using a divider might be a waste of resources. I have also read that for simple divisio...
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- The concept is this: suppose your input is x, coeff is y and you choose 14 bits resolution: c = c * 2^n/2^n; c = round(c*2^n)/2^n; the term round(c*2^n) you precompute it, call it y, then in design you multiply: x * y gives result, divide by 2^n i.e. discard n bits with/without rounding --- Quote End --- Thank you for your prompt reply. I am trying to understand that but I might be missing something... So if x = 150, c = 3 and n = 3 then y = 3*2^3 = 24 -> 150*24 = 3600 and if I shift that n positions then I get 450 when I should get something near 150/3 = 50. What did i get wrong? Edit: the result is nearly correct if I shift 2*n positions. Does it mean anything?