hey guyz!!!
doez anybody know how to change the value of a variable to Hexadecimal from decimal???
in VC++.......
thanks a lot!!!!
i need it urgently,,,,,,,,,,
pls ,,,,,,,
HELP!!!!
Printable View
hey guyz!!!
doez anybody know how to change the value of a variable to Hexadecimal from decimal???
in VC++.......
thanks a lot!!!!
i need it urgently,,,,,,,,,,
pls ,,,,,,,
HELP!!!!
Of an integer? Integers are represented as binary in memory, it only depends on you formatting how it is outputted:
printf("%x", i);
or
cout << setbase(16) << i;
thanks,,,,,, cornedbee,,
:D
hey thanks a lot cornedbee =-
but how to pack with 0's(zeros) in front???
=o)
hey nvm,,,
i tried "%04x",, it works.....
anyway thanksss,,,,,,
Use the first function, the 2 last functions will be use by the first one.
Code://Use this one
string AsciiToHex(const string &sAll)
{
string sHex;
string sTempo;
char cEach;
for (int i = 0 ; i < sAll.length() ; i++)
{
cEach = sAll.at(i);
sTempo = DecToHex((int)cEach);
sHex.append(sTempo);
sHex.append(" ");
}//End For
return sHex;
}//End AsciiToHex
//Do not use this one
string DecToHex(const int &iDecimal)
{
int i1;
char c[1];
char c2[1];
string sHexa;
i1 = abs(iDecimal / 16);
itoa(i1,c,10);
i1 = abs(iDecimal%16);
itoa(i1,c2,10);
if (i1>9)
c2[0] = ConvertH(i1);
sHexa.append(c);
sHexa.append(c2);
return (sHexa.substr(0,2));
}//End DecToHex
//Not this one either
char ConvertH(const int &iNumber)
{
switch(iNumber)
{
case 10:return 'A';break;
case 11:return 'B';break;
case 12:return 'C';break;
case 13:return 'D';break;
case 14:return 'E';break;
case 15:return 'F';break;
default:return 'X';break;
}//End switch
return 'X';
}//End ConvertH