09-05-2022, 12:02 PM
(This post was last modified: 09-05-2022, 12:04 PM by Kernelpanic.)
Interesting! Didn't even know that this is now also available in Basic.
As an example, the Egyptian or Russian pawn multiplication with the shift operator (there are only problems with the formatting of the output - it doesn't always look good):
As an example, the Egyptian or Russian pawn multiplication with the shift operator (there are only problems with the formatting of the output - it doesn't always look good):
Code: (Select All)
'Schiebeoperatoren in QBasic64 - 5. Sept. 2022
Option _Explicit
Dim As Long a, b, d1, d2, sum
Cls
Print
Print "Multipliziert zwei Zahlen nach der 'Aegyptischen Multiplikation"
Print "Auch 'russische Bauernmultiplikation' genannt"
Print
Input "Zahl 1: ", a
Input "Zahl 2: ", b
Print: Print
'Nur fuer unten folgende Ausgabe
d1 = a: d2 = b
sum = 0
While a <> 0
If a Mod 2 = 1 Then 'Wenn 'a' ungerade, dann 'b' addieren.
Print Using "#####"; b
sum = sum + b
End If
'Schiebeoperator: x >> 1=x/2, x << 1=x*2
a = _SHR(a, 1)
b = _SHL(b, 1)
Wend
Print: Print
Print Using "Das Produkt von ### * #### = #####"; d1, d2, sum
End