If you know what is hexadecimal or hex, you would definitely know what this articles is all about. If you don’t, you might want to check the below table.
Still confuse? Click Here
So let get started
#include <iostream> #include <conio.h> using namespace std; int main() { int input; cout<<"Enter a Decimal Number: "; cin>>input; cout<<"Hexadecimal: "<<hex<<input; //conversion getch(); return 0; }
Explanation
When the program run, it will ask for decimal digit and convert it into hexadecimal.
In C++, there is no need to write a complex program in order to convert decimal to hex. There is a keyword called hex which automatically convert the input number into hex. We use this keyword in the conversion line which convert the output number into hex.