Subscribe to our YouTube Channel for more Videos

How to convert Octal Number to Decimal , HexaDecimal and Binary Number using C# ?


This is my third post of the series of the Number Converter for Windows Phone 7 sourcecode . In my previous posts i talked about

In this blog post , i describe or share the code  that converts a Octal Number to Decimal , HexaDecimal and Binary Number using C# in Windows Phone 7 .

public static class OctalConverter
{
   /// <summary>
   /// Octals to binary.
   /// </summary>
   /// <param name="OctalNumber">The octal number.</param>
   /// <returns></returns>
   public static string OctalToBinary(string OctalNumber)
   {
     Int64 DecimalNumber = OctalToDecimal(OctalNumber);
     string retVal = "";
     retVal = DecimalConverter.DecimalToBinary(DecimalNumber);
     return retVal;
   }
   /// <summary>
   /// Octals to decimal.
   /// </summary>
   /// <param name="OctalNumber">The octal number.</param>
   /// <returns></returns>
   public static Int64 OctalToDecimal(string OctalNumber)
   {
     return Convert.ToInt64(Convert.ToString(Convert.ToInt64(OctalNumber,8), 10));
   }
   /// <summary>
   /// Octals to hexa.
   /// </summary>
   /// <param name="OctalNumber">The octal number.</param>
   /// <returns></returns>
   public static string OctalToHexa(string OctalNumber)
   {
     Int64 DecimalNumber = OctalToDecimal(OctalNumber);
     string retVal = "";
     retVal = DecimalConverter.DecimalToHex(DecimalNumber);
     return retVal;
   }
}

 

DecimalConverter is a static class that was described in my earlier blog post is again used . If you noticed the above sourcecode , i have tried to the .NET framework function to convert the number instead of writing my own logic … 🙂

 

 

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.