Jump to content

Ethiopian multiplication: Difference between revisions

no edit summary
(Updated to compile with Nim 1.4. Added missing parameter types. Changed "even" to "odd".)
No edit summary
Line 814:
doubleInt = Int(num * 2)
End Function</lang>
=={{header|M2000 Interpreter}}==
 
<lang Module EthiopianMultiplication{
Form 60, 25
Const Center=2, ColumnWith=12
Report Center,"Ethiopian Method of Multiplication"
// using decimals as unsigned integers
Def Decimal leftval, rightval
(leftval, rightval)=(random(1, 65535), random(1, 65536))
Print $( , ColumnWith), "Target:", leftval*rightval,
Hex leftval*rightval
a=list
sum=0
if @IsEven(leftval) Else sum+=rightval
Print leftval, rightval,
Hex leftval, rightval
while leftval>1
leftval=@halveInt(leftval)
rightval=@DoubleInt(rightval)
Print leftval, rightval,
Hex leftval, rightval
if @IsEven(leftval) Else sum+=rightval
End while
Print "", sum
Hex "", sum
Function HalveInt(i)
=Binary.Shift(i,-1)
End Function
Function DoubleInt(i)
=Binary.Shift(i,1)
End Function
Function IsEven(i)
=Binary.And(i, 1)=0
End Function
}
EthiopianMultiplicationM2000 Interpreter>
</lang>
==={{header|Microsoft Small Basic}}===
<lang microsoftsmallbasic>
404

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.