dec to hex 
Author Message
 dec to hex

hi all,
is there anyway to simply convert dec to hex i have been trying to use the
Hex function i.e.

Hex(i) where i is the decimal variable i wish to convert.i get
: error C2065: 'Hex' : undeclared identifier is the error ,and using
'hex(i)' i get   :cannot convert parameter 1 from 'int' to 'class ios &'
thanks
md



Fri, 24 Oct 2003 21:57:14 GMT  
 dec to hex
If your looking to get back a string representing the hex value, then
you can use the following snippit as a guide for C++ (you could use
sprintf also):

CString cHexValue;
int iValue;
iValue = 231;
cHexValue.Format(_T("%x"),iValue);
// cHexValue now has hex representation of iValue.  Can be zero padded
if need be.

Steve

Quote:

> hi all,
> is there anyway to simply convert dec to hex i have been trying to use the
> Hex function i.e.

> Hex(i) where i is the decimal variable i wish to convert.i get
> : error C2065: 'Hex' : undeclared identifier is the error ,and using
> 'hex(i)' i get   :cannot convert parameter 1 from 'int' to 'class ios &'
> thanks
> md



Fri, 24 Oct 2003 22:50:42 GMT  
 dec to hex
Morgan,

Are you wanting to convert an integer value (i) to a string, and have the
conversion done in base 16 (i.e. hexadecimal)?

If so, then I would suggest the _itoa(...) or the _ltoa(...) CRT functions -
they are general purpose in that that they will allow you to specify any
base, 2, 10, 16, etc...

If you are converting a decimal string to a hex string, then I am not sure -
maybe convert to integer or long using atoi(...) or atol(...) CRT function,
then covert to hex string using above.

regards
roy fine


Quote:

> hi all,
> is there anyway to simply convert dec to hex i have been trying to use the
> Hex function i.e.

> Hex(i) where i is the decimal variable i wish to convert.i get
> : error C2065: 'Hex' : undeclared identifier is the error ,and using
> 'hex(i)' i get   :cannot convert parameter 1 from 'int' to 'class ios &'
> thanks
> md



Fri, 24 Oct 2003 23:08:13 GMT  
 dec to hex
Try this

 #include <sstream>
using namespace std;

int main()
{
    int nNumber;

     std::stringstream ConverterStream( sHexValue );
     ConverterStream >> std::hex >> nNumber;

    return 0;

Quote:
}

Cheers
Check Abdoul
-----------------


Quote:

> hi all,
> is there anyway to simply convert dec to hex i have been trying to use the
> Hex function i.e.

> Hex(i) where i is the decimal variable i wish to convert.i get
> : error C2065: 'Hex' : undeclared identifier is the error ,and using
> 'hex(i)' i get   :cannot convert parameter 1 from 'int' to 'class ios &'
> thanks
> md



Fri, 24 Oct 2003 23:10:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. dec to hex conversions.....more

2. Convert Dec to Hex??

3. #define DEC or HEX?

4. #define DEC or HEX?

5. 64 Bit Dec to Hex using only 32 bit int?

6. converting hex to dec (from a file)

7. hex to dec - strtol works best!!

8. HEX to DEC IMAL problemo

9. Converting from hex to dec

10. Help... conversion of hex to dec

11. Text to Hex to Dec conversion

12. hex to dec function?

 

 
Powered by phpBB® Forum Software