Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
universal base conversion program possibly for a base conversion library later on
#12
There is an example in the wiki for converting a decimal number to binary. I have adapted it for myself to better understand it. However, I don't know up to what size the program works.

Code: (Select All)

'Dezimalzahl in Binaerformat umwandeln - 18. April 2025
'Wiki: https://qb64phoenix.com/qb64wiki/index.php/Binary

Option _Explicit

Declare Sub DezimalNachBinaer(eingabe As Long)

Dim As Long dezimalZahl

Do
  Locate 3, 3
  Input "Eingabe einer Dezimalzahl (0 fuer Beenden): ", dezimalZahl

  Locate 6, 3
  DezimalNachBinaer (dezimalZahl)
  Sleep 5: Cls
Loop Until dezimalZahl = 0

End


Sub DezimalNachBinaer (eingabe As Long)

  Dim As Integer absolutWert
  Dim As String binaerZahl, binaerZK

  If eingabe = 0 Then Exit Sub
  Do
    absolutWert = Abs(eingabe Mod 2) 'Rest wird verwendet, um Binaerzahlen zu erstellen
    eingabe = eingabe \ 2 '          Bei der Ganzzahldivision wird der Exponent von 2 um einen Faktor erhoeht.
    binaerZahl = LTrim$(Str$(absolutWert)) 'make remainder a string number
    binaerZK = binaerZahl + binaerZK '      add remainder to binary number
  Loop Until eingabe = 0

  Print "Binaerzahl: = " + binaerZK
End Sub
Reply


Messages In This Thread
RE: universal base conversion program possibly for a base conversion library later on - by Kernelpanic - 04-18-2025, 02:18 PM



Users browsing this thread: 1 Guest(s)