473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

96 bit binary to hex conversion and vice versa

hi

i want to convert a 96 bit binary number into a hexadecimal number.

e.g binary number= 00110001000101000010010101111011111101010111010001 0110000101011000101010000000000000000000000000

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
thanks and regards
akash deep batra
Jul 21 '05 #1
1 3024
"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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
3
by: mailar | last post by:
HI, Can anyone tell me how is a multi_byte to single byte and vice versa conversion done in DB2. It would be great even if someone can tell me how Oracle does it? Oracle already has functions...
3
by: Amjad | last post by:
Hi, Are there any built-in methods in VB.NET that convert one number in one format to its equivalent in another format? For example I want to convert the number 162 (decimal) to 10100010...
1
by: akash deep batra | last post by:
hi i want to convert a 96 bit binary number into a hexadecimal number. e.g binary number= 001100010001010000100101011110111111010101110100010110000101011000101010000000000000000000000000 how...
4
by: rz0 | last post by:
Hi all, This is a question about both C89 and C99 and is based on my partial reading of the standard drafts (one from before C89 but mainly N1124). If appropriate, please give a...
7
by: smith4894 | last post by:
Hello all, I'm working on writing my own streambuf classes (to use in my custom ostream/isteam classes that will handle reading/writing data to a mmap'd file). When reading from the mmap...
3
by: masood.iqbal | last post by:
Hi, Kindly excuse my novice question. In all the literature on ifstream that I have seen, nowhere have I read what happens if you try to read a binary file using the ">>" operator. I ran into...
1
by: abintoms | last post by:
Hello everyone, Can you tell me how to convert MS word documents to PDF format and vice versa.. I'm working on a project which requires me to do this.. Is there any jar files specific for this kind...
7
by: victory2006 | last post by:
like we have an integer value of : 9 and i need to convert it to binary numbers and vice versa, thanks!
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.