473,387 Members | 1,465 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,387 software developers and data experts.

96 bit binary to hexadecimal conversion

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
Nov 16 '05 #1
2 9720
ad*****@hotmail.com (akash deep batra) wrote in
news:3f*************************@posting.google.co m:
hi

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

e.g binary number=
00110001000101000010010101111011111101010111010001 011000010101100010101
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.

--
Lasse Vågsæther Karlsen
la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #2
akash deep batra <ad*****@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

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

Similar topics

4
by: arvind | last post by:
hi, How do I display a number in binary or octagonal ? eg. int a= 195; //1100 0011 int b = 87; //0101 0111 int c = a&b;//0100 0011 => bitwise and printf("%0x", c); // Here I get the...
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...
2
by: Raja | last post by:
IS there any inbuilt decimal to binary conversion function in C++
5
by: Damon | last post by:
I'm getting '', hexadecimal value 0x02, is an invalid character when I'm deseralizing XML from a 3rd party XML gateway. How do I get rid of these hexadecimal values before I deserialize? Cheers...
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...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
19
by: sethukr | last post by:
Hi everybody, Can we assign binary values to an integer variable like assigning Hexadecimal values??? Thanks, Sethu
3
by: zgfareed | last post by:
My program converts decimal numbers from to binary and hexadecimal. I am having trouble with my output which is supposed to be in a certain format. Binary needs to be in the format of XXXX XXXX...
11
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've a question regarding Hexadecimal to binary conversion. Suppose I have a long hexadecimal string, and I would like to convert it to a binary string. How can I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.