Connecting Tech Pros Worldwide Help | Site Map

Hex to Bin

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 06:48 AM
Josh Parker
Guest
 
Posts: n/a
Default Hex to Bin

What would be a good way to convert a Hex number to a Binary number.
I know all numbers stored in variables are stored as binary anyway but
how would i go about bring this out. I will be writing this info to a
pipe, which another process will then pick it up and write it to a
file.

Anyone got any advice?

  #2  
Old July 22nd, 2005, 06:48 AM
Mike Wahler
Guest
 
Posts: n/a
Default Re: Hex to Bin


"Josh Parker" <jcp1217@mail.ecu.edu> wrote in message
news:f42d5dca.0402231252.7c0791bf@posting.google.c om...[color=blue]
> What would be a good way to convert a Hex number to a Binary number.
> I know all numbers stored in variables are stored as binary anyway but
> how would i go about bring this out. I will be writing this info to a
> pipe, which another process will then pick it up and write it to a
> file.
>
> Anyone got any advice?[/color]


Roll your own function. Here's one of mine:

std::string bin(unsigned int i)
{
std::string result;
while(i)
{
result.insert(result.begin(), i % 2 + '0');
i /= 2;
}
return result;
}


-Mike


  #3  
Old July 22nd, 2005, 06:48 AM
Julie J.
Guest
 
Posts: n/a
Default Re: Hex to Bin

Are you converting it to a string representation? If not, then there is no
need to do any conversion (unless you run into endian issues).

Presuming that you want to convert it to a string representation:

Check your compiler & C library documentation. Some C libraries support
something to the effect of itoa (or _itoa) which has a radix (or base). Use 2
to convert a number to a binary string. However, itoa (et al.) are *not* ANSI
standard.


Josh Parker wrote:[color=blue]
>
> What would be a good way to convert a Hex number to a Binary number.
> I know all numbers stored in variables are stored as binary anyway but
> how would i go about bring this out. I will be writing this info to a
> pipe, which another process will then pick it up and write it to a
> file.
>
> Anyone got any advice?[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.