4 ms·
With shifts, you can multiply and divide by any number you want, as long as it's a power of two. ;)
by gary_0 3y ago
With shifts, you can multiply and divide by any number you want, as long as it's a power of two. ;)
- wvenable 3y ago"Doctor, my arm really hurts when I bend it this way, do you have any advice?" "Don't bend your arm that way" You can honestly get around not needing arbitrary multiplication and division by just avoiding numbers that aren't powers of two. No oddly sized data structures, for example. It works well unless, of course, you're building a calculator.
- whartung 3y agoYou can do it by any number if you toss in addition. If you’re multiplying by a constant, you can factor it out. For example multiply by 40 (coincidentally the number of characters per line on common microcomputers), you could shift to multiply by 32, shift to multiply by 8, and add them together. Took some additional storage but was faster, particularly for 16 bit, than a general routine.