Convert Dec to Hex??
Author Message
Convert Dec to Hex??

If you will ask a specific question about a specific subject, someone will

I can convert decimal numbers to hexadecimal numbers in dozens of ways.
Specify one.
--

Paul Lutus
www.arachnoid.com

Quote:

>How to convert Dec to Hex well in program??  Is it any function I can
>call??
>Thank you!!

Wed, 22 Aug 2001 03:00:00 GMT
Convert Dec to Hex??
I know this doesnt really answer your question, but it's better than the
other (non)reply. But it might point you in the right direction. I think
there is a way to use the Format() but I cant be sure. Hope this helps.

well for string to hex do

CString strTheString; // input
CString strHex;
CString strWork;

for ( int i = 0; i < strTheString.GetLength(); i++)
{
strWork.Format("%02X",strTheString.GetAt(i));
strHex += strWork;
strHex += " "; // the space

Quote:
}

m_Edit2 = strHex;  //output

and for hex to string

CString strHex; //input
CString strTheString;
CString strWork;
int length = m_Edit1.GetLength();
length = (length / 3) + ((length % 3) ? 1 : 0);
for(int i = 0; i < length; i++)
{
char *dummy;
unsigned strWork = strtol(m_Edit1.Mid((i * 3),2),&dummy,16);
strTheString += strWork;
}
m_Edit2 = strTheString;  //output

Quote:

> How to convert Dec to Hex well in program??  Is it any function I can
> call??
> Thank you!!

Wed, 22 Aug 2001 03:00:00 GMT
Convert Dec to Hex??
Thanks you very much!!  I would try it!!!!!!!
Quote:

> I know this doesnt really answer your question, but it's better than the
> other (non)reply. But it might point you in the right direction. I think
> there is a way to use the Format() but I cant be sure. Hope this helps.

> well for string to hex do

> CString strTheString; // input
> CString strHex;
> CString strWork;

> for ( int i = 0; i < strTheString.GetLength(); i++)
> {
>   strWork.Format("%02X",strTheString.GetAt(i));
>   strHex += strWork;
>   strHex += " "; // the space
> }
>   m_Edit2 = strHex;  //output

> and for hex to string

> CString strHex; //input
> CString strTheString;
> CString strWork;
>   int length = m_Edit1.GetLength();
>   length = (length / 3) + ((length % 3) ? 1 : 0);
>   for(int i = 0; i < length; i++)
>   {
>     char *dummy;
>     unsigned strWork = strtol(m_Edit1.Mid((i * 3),2),&dummy,16);
>       strTheString += strWork;
>   }
>   m_Edit2 = strTheString;  //output

> > How to convert Dec to Hex well in program??  Is it any function I can
> > call??
> > Thank you!!

Wed, 22 Aug 2001 03:00:00 GMT
Convert Dec to Hex??

Quote:

>How to convert Dec to Hex well in program??

Decimal number to a hex string, or decimal string to a hex string ?

for a number (in iMyNumber) to a hex string, try :

char szMyString [32];
wsprintf (szMyString, "%X", iMyNumber);

for a decimal string (in szDecString), just add atoi :

char szMyString [32];
int iMyNumber;

iMyNumber = atoi (szDecString);
wsprintf (szMyString, "%X", iMyNumber);

Bob Moore [MVP]
http://www.mooremvp.freeserve.co.uk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Due to an unreasonable amount of queries, I no
longer answer unsolicited email questions. Sorry,
no exceptions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Wed, 22 Aug 2001 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages