Hexadecimal to Octal Conversion” is a one of the classic programming problem exercise. Here, we are given a hexadecimal number, entered by user and our task is to write a program to convert the given hexadecimal number to its equivalent octal number.

```HEXADECIMAL = 32A
OCTAL = 1452```

The steps required for Hexadecimal to Octal Conversion are as follows:

1. Scan the hexadecimal number from left to right digit by digit.
2. Convert each digit of hexadecimal number into its corresponding 4-digit binary number, combine them and store it into temporary variable ‘hexadecimal_binary’.
3. Make sure the number of digits of ‘hexadecimal_binary’ are divisible by 3. If not, add extra remaining 0s in the front of ‘hexadecimal_binary’.
4. Now, distribute the ‘hexadecimal_binary’ into pairs of 3-digit binary numbers.
5. Then, convert each 3-digit pair into corresponding Octal number.
6. Combine the character and get the result.
7. Print the result.

#### C++ Program for hexadecimal to octal Conversion is as follows:

```/* C++ Program for Hexadecimal to Octal Conversion */
#include<bits/stdc++.h>
using namespace std;
int bin2Dec(string binary)
{
int decimal = 0;
int iterator = 2;
for(int i = 0; i < 3; i++)
{

char digit = binary[i];
if(digit == '1')
decimal = decimal + (1 * pow(2,iterator)); /* Putting it into formula */
iterator--;
}
return decimal;
}
int main()
{
/* Scan the hexadecimal Number */

/* Converting each digit of hexadecimal number
to 4-digit binary number and store the
*/
for(int i = 0; i < Hexadecimal.length(); i++)
{
string temp;
{
case '0': temp = "0000";
break;
case '1': temp = "0001";
break;
case '2': temp = "0010";
break;
case '3': temp = "0011";
break;
case '4': temp = "0100";
break;
case '5': temp = "0101";
break;
case '6': temp = "0110";
break;
case '7': temp = "0111";
break;
case '8': temp = "1000";
break;
case '9': temp = "1001";
break;
case 'A': temp = "1010";
break;
case 'B': temp = "1011";
break;
case 'C': temp = "1100";
break;
case 'D': temp = "1101";
break;
case 'E': temp = "1110";
break;
case 'F': temp = "1111";
}
/* Combining the 3-digit binary numbers */
}

/* Length of 'hexadecimal_binary' must be multiple of 3 */
{
/* Inserting Extra 0s in front, if needed */
{
}
}

/* Distribute 'hexadecimal_binary' into pairs of 3-digit,
convert them into decimal equivalent which will be octal
equivalent
*/
string Octal;
for(int i = 0; i < hexadecimal_binary.length(); i=i+3)
{
string temp = "";

/* Converting 'temp' into decimal */
int decimal = bin2Dec(temp);

/* Converting decimal to corresponding Hexadecimal */
switch(decimal) {
case 0 :
Octal = Octal + '0';
break;
case 1 :
Octal = Octal + '1';
break;
case 2 :
Octal = Octal + '2';
break;
case 3 :
Octal = Octal + '3';
break;
case 4 :
Octal = Octal + '4';
break;
case 5 :
Octal = Octal + '5';
break;
case 6 :
Octal = Octal + '6';
break;
case 7 :
Octal = Octal + '7';
break;
}
}

/* Truncating Extra 0s from beginning, if any */
while(Octal=='0')
{
Octal.erase(Octal.begin()+0);
}

/*Printing the result */
cout<<"The Octal of "<<Hexadecimal<<" is "<<Octal;
}

```
```OUTPUT: