473,659 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

96 bit binary to hexadecimal conversion

hi

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

e.g binary number= 001100010001010 000100101011110 111111010101110 100010110000101 011000101010000 000000000000000 000000

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 = 3114257BF574585 62A000000
thanks and regards
akash deep batra
Nov 16 '05 #1
2 9747
ad*****@hotmail .com (akash deep batra) wrote in
news:3f******** *************** **@posting.goog le.com:
hi

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

e.g binary number=
001100010001010 000100101011110 111111010101110 100010110000101 01100010101
000000000000000 0000000000

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 = 3114257BF574585 62A000000
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*****@hotmai l.com> wrote:
i want to convert a 96 bit binary number into a hexadecimal number.

e.g binary number= 001100010001010 000100101011110 111111010101110 1000
101100001010110 001010100000000 000000000000000 00

how can i do that in C#.
Use Convert.ToInt32 (theString, 2) to parse from binary, and
Convert.ToStrin g(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 = 3114257BF574585 62A000000


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

--
Jon Skeet - <sk***@pobox.co m>
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
22154
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 hexagonal output //I want to get the binary output of char c
1
3107
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 can i do that in C#. also i want to convert a hexadecimal number (24 digits) into a binary number
2
16042
by: Raja | last post by:
IS there any inbuilt decimal to binary conversion function in C++
5
7902
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 Damon
3
17876
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 (binary) or to A2 (hexadecimal) and vice versa. Thanks.
7
19212
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 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
19
18824
by: sethukr | last post by:
Hi everybody, Can we assign binary values to an integer variable like assigning Hexadecimal values??? Thanks, Sethu
3
8839
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 for numbers 0 to 255. What am doing wrong or not doing with my output? Source code: // code #include <iostream>
11
7686
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 accomplish this with minimal code? I've seen other posts, but they are restricted to the size of the hexadecimal string, for they use Convert.ToString(...). EXA:
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.