Forum Discussion
Altera_Forum
Honored Contributor
15 years agobit shifting arithmetic
Hi there! I am trying to get my around some binary arithmetic. Basically, I don't want to deal with floating points, so I have a problem that was originally 400 * 0.0615 = 24.6 ...
Altera_Forum
Honored Contributor
15 years agoBack to your original example:
--- Quote Start --- Basically, I don't want to deal with floating points, so I have a problem that was originally 400 * 0.0615 = 24.6 to this (400*615) >> 4 = 24.6 --- Quote End --- Instead of multiplying 0.0615 by 10000, multiply by a power of 2. For example: = 400 * (0.0615 * 2^16) >> 16 = 400 * 4030 >> 16 = 1612000 >> 16 = 24 If you want to avoid floats and still have fractional values, you will have to use fixed point.