96 bit binary to hexadecimal conversion

A

akash deep batra

hi

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

e.g binary number= 001100010001010000100101011110111111010101110100010110000101011000101010000000000000000000000000

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
 
L

Lasse Vågsæther Karlsen

(e-mail address removed) (akash deep batra) wrote in
hi

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

e.g binary number=
00110001000101000010010101111011111101010111010001011000010101100010101
0000000000000000000000000

how can i do that in C#.

Take every four bits and convert to a hexadecimal digit:

0000 -> 0
0001 -> 1
....
0100 -> 8
....
1111 -> F

and so on. If the binary number does not contain a number of digits
evenly divisible by 4, pad with 1-3 0's at the start before starting the
conversion.
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

Do the opposite :) Take every hexadecimal digit and replace with its 4-
digit binary counterpart.
 
J

Jon Skeet [C# MVP]

akash deep batra said:
i want to convert a 96 bit binary number into a hexadecimal number.

e.g binary number= 0011000100010100001001010111101111110101011101000
10110000101011000101010000000000000000000000000

how can i do that in C#.

Use Convert.ToInt32 (theString, 2) to parse from binary, and
Convert.ToString(theNumber, 16) to format in hex.

This allows you to do 32 bits at a time - so break your binary number
after each 32 bits, and reassemble appropriately.
also i want to convert a hexadecimal number (24 digits) into a binary
number

e.g
hex number = 3114257BF57458562A000000

Same as above but with the 2 and 16 the other way round.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top