convert int to hex

bwells

Well-known member
Joined
Feb 25, 2003
Messages
84
I have an integer value and I want to convert the value to a hex number. I think I can use the cin >> operator but I am not sure of the syntax. Can someone tell me an easy way to do this conversion?
 
Use itoa to convert from an int to a string buffer. The function takes a parameter which specifies which base to represent the number in. Pass it 16 for hexadecimal.
 
Dont Know if it is still of use to you, but try this if it is:

int main()
{
cout.unsetf(ios::dec);
cout.setf(ios::hex);

cout << 100;

cin.get();
return 0;
}

This changes how cout looks at integers. You can also develop formatted i/o using many other format flags. You should really check it out. While you are at it, you should check out i/o manipulators...they make the code a lot more user friendly.
 
Back
Top