>Ho bisogno all'interno di un'applicazione web Asp.Net di convertire
>un codice binario in esadecimale e viceversa. Qualcuno può darmi
>una mano? Grazie
Mi sono dovuto fare una classe apposta non conoscendo altre vie, fino a che ho scoperto la BitConverter
Le funzioni che mi sono fatto sono:
Converte un array di byte in stringa esadecimale:
Private Shared Function GetHex(ByVal value As Byte()) As String
Dim sb As New System.Text.StringBuilder()
Dim b As Byte
For Each b In value
sb.Append(String.Format("{0:x2}", b).PadLeft(2, "0"c))
Next
Return sb.ToString()
End Function
Converte una stringa esadecimale in un array di byte
Private Shared Function GetBytesFromHex(ByVal value As String) As Byte()
Dim arrByte(Convert.ToInt32(value.Length / 2) - 1) As Byte
For i As Int32 = 0 To arrByte.Length - 1
arrByte(i) = Convert.ToByte(Convert.ToInt32(value.Substring(i * 2, 2), 16))
Next
Return arrByte
End Function
uso quelle per ora, ma se vuoi dare un'occhiata alla BitConverter guarda il link seguente:
http://msdn2.microsoft.com/en-us/library/system.bitconverter.aspx
ciao!
Alx81 =)
http://blogs.dotnethell.it/suxstellino