#include <iostream> #include<cmath> #include<ctime> #include<string> #include <iomanip> #include <fstream> using namespace std; int hexDec(const string& hex); int hexCharToDecimal(char ch); int main() { cout << "enter a hex Number "; string hex; cin >> hex; cout << "The Decimal Number For Hex Is " << hex << " is " << hexDec(hex) << endl; } int hexDec(const string& hex) { int decimalValue = 0; for (unsigned i = 0; i < hex.length(); i++) { decimalValue = decimalValue * 16 + hexCharToDecimal(hex[i]); } return decimalValue; } int hexCharToDecimal(char ch) { ch = toupper(ch); if (ch >= 'A' && ch <= 'F') return 10 + ch - 'A'; else return ch - '0'; }