C++ Programming Code Examples C++ > Conversions Code Examples Convert Octal number to Hexadecimal number Convert Octal number to Hexadecimal number To convert octal number to hexadecimal number in C++ programming, you have to ask to the user to enter the octal number to convert it into hexadecimal to display the equivalent value in hexadecimal form as shown here in the following program. Following C++ program ask to the user to enter any octal number to convert it into hexadecimal number, then display the result on the screen: #include<iostream.h> #include<conio.h> #include<string.h> #include<math.h> void main() { clrscr(); int a[20], b[20], c[20], rev[20], h, i, j, k, l, x, fra, flag, rem, number1, number3; float rem1, number2, number4, dno; char s[20]; x = fra = flag = rem = 0; rem1 = 0.0; cout<<"Enter any Octal Number : "; cin>>s; for(i=0,j=0,k=0; i<strlen(s); i++) { if(s[i]=='.') { flag=1; } else if(flag==0) { a[j++]=s[i]-48; } else if(flag==1) { b[k++]=s[i]-48; } } x=j; fra=k; for(j=0,i=x-1; j<x; j++,i--) { rem = rem +(a[j] * pow(8,i)); } for(k=0,i=1;k<fra;k++,i++) { rem1 = rem1 +(b[k] / pow(8,i)); } rem1 = rem + rem1; dno = rem1; number1 = (int)dno; number2 = dno - number1; i=0; while(number1!=0) { rem = number1 % 16; rev[i] = rem; number1 = number1 /16; i++; } j=0; while(number2!=0.0) { number2 = number2 * 16; number3 = (int)number2; number4 = number2 - number3; number2 = number4; a[j] = number3; j++; if(j==4) { break; } } l=i; cout<<"\nEquivalent Hexadecimal Value = "; for(i=l-1; i>=0; i--) { if(rev[i]==10) { cout<<"A"; } else if(rev[i]==11) { cout<<"B"; } else if(rev[i]==12) { cout<<"C"; } else if(rev[i]==13) { cout<<"D"; } else if(rev[i]==14) { cout<<"E"; } else if(rev[i]==15) { cout<<"F"; } else { cout<<rev[i]; } } h=j; cout<<"."; for(k=0; k<h; k++) { if(a[k]==10) { cout<<"A"; } else if(a[k]==11) { cout<<"B"; } else if(a[k]==12) { cout<<"C"; } else if(a[k]==13) { cout<<"D"; } else if(a[k]==14) { cout<<"E"; } else if(a[k]==15) { cout<<"F"; } else { cout<<a[k]; } } getch(); }