Something that I had heard of some time ago was a non standard way of
performing multiplication that was called Russian multiplication. I
found the following article on a web site so I coded it and it works fine.
The size limit is DWORD range which is normal with DWORD size parameters.
On computer I think there are other way to do this operation that are faster
but it is an interesting technique and I would like to see more of these
techniques if I can find them.
I wonder if any of the members know anything about Russian maths ?
Regards,
[email protected]
------------------
performing multiplication that was called Russian multiplication. I
found the following article on a web site so I coded it and it works fine.
The size limit is DWORD range which is normal with DWORD size parameters.
On computer I think there are other way to do this operation that are faster
but it is an interesting technique and I would like to see more of these
techniques if I can find them.
I wonder if any of the members know anything about Russian maths ?
Regards,
[email protected]
Code:
The article ~~~~~~~~~~~ =========================================================================== What is Russian multiplication? Russian or Peasant multiplication is multiplication by repeated doubling. Example: to multiply 17 by 13 you double the 17 and halve the 13, and add the doubles that correspond to an odd number in the other column. 17 * 13 doubled and halved: 34 * 6 doubled and halved: 68 * 3 doubled and halved: 136 * 1 221 = 17 x 13 - adding up the numbers in the first column that correspond to an odd number in the second (17+68+136) It's a handy way of writing long multiplication in binary. =========================================================================== The code to perform the multiplication. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LOCAL num1 as DWORD LOCAL num2 as DWORD LOCAL tst1 as DWORD LOCAL tst2 as DWORD LOCAL rslt as DWORD ' ------------------------------------- ' the two numbers to multiply together ' ------------------------------------- num1 = 99999 num2 = 42111 tst1 = num1 tst2 = num2 rslt = 0 ! mov ecx, num1 ! mov edx, num2 ! xor ebx, ebx ; ebx is for results nxt0: ! test edx, 1 ; test if EDX is even ! jz nxt1 ! add ebx, ecx ; add 1st number to result nxt1: ! add ecx, ecx ; double ! shr edx, 1 ; half ! cmp edx, 1 ; test EDX for 1 ! jne nxt0 ; loop if not nxt2: ! add ebx, ecx ! mov rslt, ebx MessageBox hWin,str$(rslt),str$(tst1*tst2), _ %MB_OK or %MB_ICONINFORMATION
Comment