C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hex to Bin

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Josh Parker
Guest





PostPosted: Mon Feb 23, 2004 8:52 pm    Post subject: Hex to Bin Reply with quote



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?
Back to top
Mike Wahler
Guest





PostPosted: Mon Feb 23, 2004 10:20 pm    Post subject: Re: Hex to Bin Reply with quote




"Josh Parker" <jcp1217 (AT) mail (DOT) ecu.edu> wrote

Quote:
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?


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



Back to top
Julie J.
Guest





PostPosted: Mon Feb 23, 2004 10:26 pm    Post subject: Re: Hex to Bin Reply with quote



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:
Quote:

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?

Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group