Autor Beitrag
DareDevil
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Windows7
C# (VS 2010)
BeitragVerfasst: Di 22.08.06 19:47 
Habe schon wieder ein Problem!

Ich möchte einen Hex-String

ausblenden Quelltext
1:
4861206c6c6f					


wieder in die Zeichenfolge umwandeln.

Greez

Pascal
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 23.08.06 12:56 
Wenn etwas ausnahmsweise mal nicht schon in der FCL vorhanden ist, muss man eben selbst Hand anlegen ;) .
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
      static byte[] HexToBytes(string hexStream)
    {
      byte[] result = new byte[hexStream.Length / 2 - hexStream.Length % 2];

      for (int i = 0; i < result.Length; i++) {
        result[i] = byte.Parse(hexStream.Substring(i * 22), System.Globalization.NumberStyles.HexNumber);
      }

      return result;
    }

+
Encoding.Default.GetString
DareDevil Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Windows7
C# (VS 2010)
BeitragVerfasst: Mi 23.08.06 15:21 
Selbst habe ich ja schon Handangelegt aber ich hatte einen etwas zulangen Algo

und der ist halt kürzer und besser als meiner.

Er funktioniert perfekt. THX

Greez

Pascal
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 24.08.06 12:12 
Bittschön :)
Bevor ichs vergesse: bei einer ungeraden Zeichenanzahl wird von meiner Methode das letzte Zeichen verworfen.
DareDevil Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70

Windows7
C# (VS 2010)
BeitragVerfasst: Do 24.08.06 14:33 
Ungerade kann ja eigentlich nicht sein weil eine Hex zahl hat ja immer 2Zeichen
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Do 24.08.06 18:54 
Genau aus diesem Grund wird ja das letzte Zeichen ggf. verworfen :zwinker: .