Convert Decimal to Hexadecimal Program in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ program to Convert Decimal to Hexadecimal

To convert binary to hexadecimal in C++ Program, we have to ask to the user to enter any number in binary to convert it into hexadecimal, then display the equivalent hexadecimal value on the screen.

Binary Numbers: Binary number Base is 2 because Binary numbers is 0 and 1. Examples of Decimal Number is 110, 111, 1011, 1111, 1010 etc

Hexadecimal Numbers: Hexadecimal number Base is 16 because Hexadecimal represent value of 0 to 9 and A to F. Examples of Hexadecimal Number is 1E, F, 3E8, 5A... etc.


Input Binary Number : 1011
Euivalent Hexadecimal Number : B

Input Binary Number : 11011
Euivalent Hexadecimal Number : 1B

Input Binary Number : 11110
Euivalent Hexadecimal Number : 1E

Algorithom to Convert Binary to Hexadecimal

  • Divide the number by 16.
  • Get the integer quotient for the next iteration.
  • Get the remainder for the hex digit.
  • Repeat the steps until the quotient is equal to 0.

C++ program to convert Binary to Hexadecimal

#define 1000

void main()
        char binnum[MAX], hexa[MAX];
        int temp;
        long int i=0,j=0;
        cout<<"Enter any Binary Number: ";
          binnum[i] = binnum[i] -48;
          temp =  binnum[i-3] *8 + binnum[i-2] *4 +  binnum[i-1] *2 + binnum[i] ;
          if(temp > 9)
          hexa[j++] = temp + 55;
            hexa[j++] = temp + 48;
        if(i ==1)
          hexa[j] = binnum[i-1] *2 + binnum[i] + 48 ;
        else if(i==0)
          hexa[j] =  binnum[i] + 48 ;
        cout<<"Equivalent Hexadecimal Number is: \n";


Enter any Binary Number : 10011
Equivalent Hexadecimal Number is: 13
cpp program to convert binary to hexadecimal
Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements

Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: or 8076671483 Try this Keyword C++ Programs