Program in C++ to Convert Hexadecimal to Decimal number Using Function
#include<iostream> #include<string.h> #include<iomanip> using namespace std; int HexaToDec(char *ch) { int i,base=1,temp,dec=0; i=strlen(ch)-1; while(i>=0) { if(ch[i]>='A'&&ch[i]<='F') temp=int(ch[i])-55; else temp=int(ch[i])-48; dec+=temp*base; base*=16; i--; } return (dec); } int main() { char ch[3]="1A"; cout<<"Enter a Hexadecimal number:-"; char hexa[100]; cin>>hexa; cout<<"Decimal No.="<<HexaToDec(hexa); return 0; }
Output:-
0 Comments