C++ Program to convert Hexadecimal to Decimal
Write C++ Program to convert Hexadecimal to Decimal
// CPP Program to convert Hexadecimal to Decimal
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n, ans = 0;
cout << "Enter the Hexadecimal number :--> ";
cin >> n;
int i = 0;
while(n != 0)
{
int digit = n % 10;
ans = ans + (digit* pow(16,i));
n = n / 10;
i++;
}
cout << "The Decimal number is :--> " << ans;
return 0;
}
Output:
Enter the Hexadecimal number :--> 658
The Decimal number is :--> 1624