I know how to type cast from int to char, but how would you do the same thing from int to hex, any ideas, thanks in advance...
I know how to type cast from int to char, but how would you do the same thing from int to hex, any ideas, thanks in advance...
It certainly wouldn't be typecasting. char and int are data types, and hex is not a data type. As far as C++ is concerned, hex is just a format in which to print numbers. Search the boards - there have been many discussions on the subject of going the other way, and these should give you some ideas.
>but how would you do the same thing from int to hex
Any questions? The only difference between decimal and hexadecimal is how you represent the value. 27 and 1B are the same exact same value, they're just represented in a different way (such as when you print with the hex modifier).Code:int dec = 27; int hex = dec;
My best code is written with the delete key.
...what they said.
If you want to output an int value in hex format you can do this:
Should output: 20Code:#include <iostream> #include <iomanip> ... int value = 32; std::cout << std::hex << value << std::endl;
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
and if you want to show the base output std::showbase to the stream so it would show 0x20Originally Posted by hk_mp5kpdw
nextus, the samurai warrior