// C# Program for the above approach
using System;
using System.Collections.Generic;
namespace HexToOctConverter
{
class Program
{
static string HexToOct(string hexNum)
{
// Map containing hexadecimal to decimal conversion
Dictionary<char, int> hexToDecMap = new Dictionary<char, int>(){
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3},
{'4', 4}, {'5', 5}, {'6', 6}, {'7', 7},
{'8', 8}, {'9', 9}, {'A', 10}, {'B', 11},
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}
};
// Converting hexadecimal number to decimal
int decimalNum = 0;
foreach (char digit in hexNum)
{
decimalNum = decimalNum * 16 + hexToDecMap[digit];
}
// Converting decimal number to octal
string octalNum = "";
while (decimalNum > 0)
{
int octalDigit = decimalNum % 8;
octalNum = octalDigit.ToString() + octalNum;
decimalNum /= 8;
}
return octalNum;
}
static void Main(string[] args)
{
string hexNum = "1AC";
Console.WriteLine(HexToOct(hexNum));
Console.ReadLine();
}
}
}
// This code is contributed by princekumaras