|
-
Sep 19th, 2002, 04:03 AM
#1
Thread Starter
Member
Dec ----to----> Hex <<urgent>>
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!!!!
-
Sep 19th, 2002, 05:00 AM
#2
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;
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 19th, 2002, 05:02 AM
#3
Thread Starter
Member
thanks,,,,,, cornedbee,,
-
Sep 19th, 2002, 05:17 AM
#4
Thread Starter
Member
hey thanks a lot cornedbee =-
but how to pack with 0's(zeros) in front???
=o)
-
Sep 19th, 2002, 05:21 AM
#5
Thread Starter
Member
hey nvm,,,
i tried "%04x",, it works.....
anyway thanksss,,,,,,
-
Sep 19th, 2002, 05:45 AM
#6
Ya ya Baby!!!Me is Back
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|