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

Ask a meaningful question, get a meaningful answer.

If you will ask a specific question about a specific subject, someone will
provide a specific answer.

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  
 
 [ 4 post ] 

 Relevant Pages 

1. converting hex to dec (from a file)

2. Converting from hex to dec

3. Summary: Converting ascii hex to pure hex values

4. Converting ascii hex values to hex bytes

5. Need Help: Converting from hex to integer and back to hex

6. hex to dec - strtol works best!!

7. HEX to DEC IMAL problemo

8. Help... conversion of hex to dec

9. Text to Hex to Dec conversion

10. hex to dec function?

11. dec to hex conversions.....more

12. hex to dec

 

 
Powered by phpBB® Forum Software