Potenzmenge.vbs 843 B

1234567891011121314151617181920212223242526272829303132
  1. Option Explicit
  2. Dim Ausgabe, i, BinWert, Summe, j, k
  3. Dim Menge, Liste1(), Liste2()
  4. Menge = InputBox("Gib eine Menge ein.")
  5. ReDim Liste1(Len(Menge))
  6. Ausgabe = ""
  7. For i = 1 To Len(Menge)
  8. BinWert = ""
  9. Dim AsciiWert
  10. AsciiWert = Asc(Mid(Menge, i, 1))
  11. Do While AsciiWert > 0
  12. BinWert = CStr(AsciiWert Mod 2) & BinWert
  13. AsciiWert = AsciiWert \ 2
  14. Loop
  15. ' Auffüllen auf 8 Bit
  16. BinWert = String(8 - Len(BinWert), "0") & BinWert
  17. Ausgabe = Ausgabe & BinWert & vbCrLf
  18. Next
  19. 'MsgBox "Potenzmenge (Binärcode):" & vbCrLf & Ausgabe, vbInformation, "Ergebnis"
  20. ReDim Liste2(Len(Ausgabe))
  21. For j = 1 To Len(Ausgabe)
  22. Liste2(j) = Mid(Ausgabe, j, 1)
  23. For k = LBound(Liste2) To UBound(Liste2)
  24. Summe = Liste1(k) + Summe
  25. Next
  26. MsgBox "Summe :" & Summe, vbInformation, "Ergebnis"
  27. Next