java - How can I perform multiplication without the '*' operator? -
i going through basic stuff learning c. came upon question multiply number 7 without using * operator. it's this
(x << 3) - x;
now know basic bit manipulation operations, can't how multiply number other odd number without using * operator? there general algorithm this?
think how multiply in decimal using pencil , paper:
12 x 26 ---- 72 24 ---- 312
what multiplication in binary?
0111 x 0101 ------- 0111 0000 0111 ------- 100011
notice anything? unlike multiplication in decimal, need memorize "times table," when multiplying in binary, multiplying 1 of terms either 0 or 1 before writing down in list addends. there's no times table needed. if digit of second term 1, add in first term. if it's 0, don't. note how addends progressively shifted on left.
if you're unsure of this, few binary multiplications on paper. when you're done, convert result decimal , see if it's correct. after you've done few, think you'll idea how binary multiplication can implemented using shifts , adds.
Comments
Post a Comment