48558
Feb 12, 2008, updated at Feb 13, 2008 (UTC)
16713
2
0
String in Binär umwandeln
Hallo,
Ich würde gerne mit VBScript einen String in Binär und zurück umwandeln .
Wie kann ich das realisieren?
Ich würde gerne mit VBScript einen String in Binär und zurück umwandeln .
Wie kann ich das realisieren?
Please also mark the comments that contributed to the solution of the article
Content-Key: 80593
Url: https://administrator.de/contentid/80593
Printed on: April 24, 2024 at 12:04 o'clock
2 Comments
Latest comment
Hallo Yugius!
Etwa so:
Zum Testen solltest Du das Script über "cscript" starten.
Grüße
bastla
Etwa so:
Text = "Nur ein Test."
WScript.Echo Text
'Zeichenweise Umwandlung in Bin
Bin = ""
For i = 1 To Len(Text)
Dec = Asc(Mid(Text, i, 1))
Bin = Bin & Dec2Bin(Dec)
Next
WScript.Echo Bin
'Byteweise Umwandlung in Zeichen
Text = ""
For i = 1 To Len(Bin) Step 8
Text = Text & Chr(Bin2Dec(Mid(Bin, i, 8)))
Next
WScript.Echo Text
Function Dec2Bin(D) 'Umwandlung eines dezimalen Wertes zwischen 0 und 255 in Binärdarstellung
By = ""
For a = 7 To 0 Step -1
Bit = Int(D / 2 ^ a)
D = D - Bit * 2 ^ a
By = By & CStr(Bit)
Next
Dec2Bin = By
End Function
Function Bin2Dec(By) 'Umwandlung einer Binär-Zahl (8 Bit) in Dezimaldarstellung
If Len(By) <> 8 Then Err.Raise 5
D = 0
For a = 0 To 7
D = D + Mid(By, 8 - a, 1) * 2 ^ a
Next
Bin2Dec = D
End Function
Grüße
bastla