Rubrik: Variablen/Strings · Algorithmen/Mathematik | VB-Versionen: VB4, VB5, VB6 | 02.03.07 |
Zahlensystem konvertieren II Konvertiert Zahlen vom Zehner-System in Zahlensysteme vom 2er - 36er System. | ||
Autor: Wolfgang Wolf | Bewertung: | Views: 9.229 |
www.ww-a.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Ich habe den Tipp Zahlensystem konvertieren im vb@rchiv Newsletter gelesen und möchte diesen erweitern. Der Tipp hört bei hexadezimal, System = 16 auf. Ich verwende eine ähnliche Prozedur, allerdings bis System = 36, um große Serriennummern platzsparrend auf Schilder unterzubringen. So wird z.B aus 2147483647 (max. Long) ein kurzes "ZIK0ZJ".
Private Function GetBitsEx(ByVal bt As Long, _ ByVal system As Integer) As String Dim z As Long Dim nZ As String Dim neg As Boolean If (system > 36) Or (system < 2) Then GetBitsEx = "Falsches Zahlensystem" Exit Function End If If bt < 0 Then neg = True bt = Abs(bt) End If Do z = bt Mod system If z < 10 Then nZ = CStr(z) & nZ Else nZ = Chr(55 + z) & nZ bt = bt - z If bt = 0 Then Exit Do Else bt = bt / system Loop If neg Then GetBitsEx = "-" & nZ Else GetBitsEx = nZ End If End Function