Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
arduno
Anmeldungsdatum: 12.05.2011 Beiträge: 252
|
Verfasst am: 18.10.2014, 15:58 Titel: Text-Hex-Zahlen in einem Wert umwandeln. |
|
|
Hallo, guten Tag .
Ich möchte bitte aus diesem Text Hexzahlen auslesen und in einem Wert umwandeln :
00 01 02 03 04 05 06 07
08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17
18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27
Wie kann man das bitte auslesen und umwandeln?
Danke.
Gruss |
|
Nach oben |
|
 |
RockTheSchock
Anmeldungsdatum: 04.04.2007 Beiträge: 138
|
Verfasst am: 18.10.2014, 16:47 Titel: |
|
|
Code: | 'Zähle Anzahl der Hex Bytes
Function countHexBytes(text As String) As Integer
Dim As Integer hexcounter
If Len(text)>0 Then
For i As Integer = 0 To Len(text)-1
Select Case text[i]
Case 48 To 57, 97 To 102 ,65 To 70 '"0" To "9", "a" To "f", "A" To "F"
hexcounter += 1
End Select
Next
hexcounter= hexcounter/2
End If
Return hexcounter
End Function
Sub ReadHexbytes(text As String,hexbytearray() As UByte)
Dim As Integer hexbytes
hexbytes= countHexBytes(text)
If hexbytes<1 Then Return
ReDim hexbytearray(countHexBytes(text)-1)
Dim As Integer i,h
for i= 0 To Len(text)-1
Select Case text[i]
Case 48 To 57, 97 To 102 ,65 To 70 '"0" To "9", "a" To "f", "A" To "F"
hexbytearray(h) = val("&H"+Chr(text[i])+Chr(text[i+1]))
h=h+1
i=i+1
Continue for
End Select
Next
End Sub
Sub PrintHexbytes(hexbytearray() As UByte)
For i As Integer = LBound(hexbytearray) To UBound(hexbytearray)
Print i,hexbytearray(i)
Next
End Sub
Dim hbarray(Any) As Ubyte
Dim text As String
text="00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"
text+="10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F"
text+="20 21 22 23 24 25 26 27"
Cls
ReadHexbytes text,hbarray()
PrintHexbytes hbarray()
Sleep |
|
|
Nach oben |
|
 |
nemored

Anmeldungsdatum: 22.02.2007 Beiträge: 4699 Wohnort: ~/
|
Verfasst am: 18.10.2014, 16:57 Titel: |
|
|
Man muss ja nicht alles selber machen.
Code: | dim as string txt = "7f"
print valint("&h" & txt) |
_________________ Deine Chance beträgt 1:1000. Also musst du folgendes tun: Vergiss die 1000 und konzentriere dich auf die 1. |
|
Nach oben |
|
 |
arduno
Anmeldungsdatum: 12.05.2011 Beiträge: 252
|
Verfasst am: 18.10.2014, 18:08 Titel: |
|
|
Jup danke.
Gruss |
|
Nach oben |
|
 |
|