"akash deep batra" <ad*****@hotmail.com> schrieb
hi
i want to convert a 96 bit binary number into a hexadecimal
number.
e.g binary number=
00110001000101000010010101111011111101010111010001 01100001010110001010100000
00000000000000000000
how can i do that in C#.
also i want to convert a hexadecimal number (24 digits) into a
binary number
e.g
hex number = 3114257BF57458562A000000
Sorry, VB.Net code: ;-)
(quick&dirty without checks)
Private Function BinStringToHexString(ByVal Text As String) As String
Static sb As New System.Text.StringBuilder(24)
sb.Length = 0
For i As Integer = 0 To 3
sb.Append( _
Convert.ToInt32(Text.Substring(i * 24, 24), 2).ToString("X6") _
)
Next
Return sb.ToString
End Function
Private Function HexStringToBinString(ByVal Text As String) As String
Static table As String() = _
{"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", _
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"}
Static sb As New System.Text.StringBuilder(96)
sb.Length = 0
'Stop
For i As Integer = 0 To 23
Dim b As Integer
b = Convert.ToInt32(Text.Chars(i))
Select Case b
Case 48 To 57
sb.Append(table(b - 48))
Case Else
sb.Append(table(b - 55))
End Select
Next
Return sb.ToString
End Function
--
Armin
How to quote and why:
http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html