Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Factorial
#1
QB64 has had _Shl and Shr for a while now, they are useful for quick multiply/divide by a power of 2, here'a factorial using only addition/subtraction and shifts
I can't think of a practical use for rol and ror
Code: (Select All)
Dim As _Integer64 N, b, c, p
Dim As Long i
For i = 0 To 20
    N = i
    c = N - 1
    p = 1
    While c > 0
        p = 0
        b = c
        While b > 0
            If b And 1 Then
                p = p + N
            End If
            b = _ShR(b, 1)
            N = _ShL(N, 1)
        Wend
        N = p
        c = c - 1
    Wend
    Print i; "! = "; p
Next
Reply


Messages In This Thread
Factorial - by Jack - 09-05-2022, 04:01 AM
RE: Factorial - by Kernelpanic - 09-05-2022, 12:02 PM
RE: Factorial - by Jack - 09-05-2022, 12:12 PM
RE: Factorial - by Kernelpanic - 09-05-2022, 12:51 PM



Users browsing this thread: 2 Guest(s)