Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HEX to Decimal and Decimal to Hex

Status
Not open for further replies.

youssef

Programmer
Mar 13, 2001
96
BE
How I do to convert a decimal value to Hexa value and Hexa to Decimal value ?

Thanks
 
the decimal value is equivalent to hex... i dont completely follow what you mean.

int x = 255;
cout<<x<<endl<<hex<<x

will output

255
ff

you may also want to look into strtol... but I am not sure what you are trying to do.

Matt
 
Thank for help:

My source code for converting a hex string to decimal is :

// conversion hexa to decimal
{
char *temp;
UpdateData(TRUE);
m_dec = strtoul( m_hex, &temp, 16 );
UpdateData(FALSE);
}
m_hex is a editbox (CString)
and
m_dec is a editbox (long)

 
Not sure this will work as strtoul is looking for a char*

strtoul( m_hex, &temp, 16 );


Maybe try

m_dec = strtoul( (LPCTSTR)m_hex, &temp, 16 );


Matt





 
Anny number variables are binary. Theirs string representation can be binary, octal/decimal/hexadecimal. If you want to use strings, you can use sptintf for char*, operator<< for ostreams:
char* x[50];
fprintf(x,&quot;dec-%d, hex \x%d&quot;,OneNumber,OneNumber);
do you see? you use the same OneNumber.
ostrstream xx;
xx<<&quot;dec value &quot;<<dec<<OneNumber<<endl<<&quot;hex value &quot;<<hex<<OneNumber<<flush; John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top