gray laptop computer showing html codes in shallow focus photography

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

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

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

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

public static class HexaConverter
{
   /// <summary>
   /// Hex2binaries the specified hexvalue.
   /// </summary>
   /// <param name="hexvalue">The hexvalue.</param>
   /// <returns></returns>
   public static string hex2binary(string hexvalue)
   {
      string binaryval = "";
      binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2);
      return binaryval;
   }

   /// <summary>
   /// Hex2s the decimal.
   /// </summary>
   /// <param name="hexvalue">The hexvalue.</param>
   /// <returns></returns>
   public static string hex2Decimal(string hexvalue)
   {
      string binaryval = "";
      binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 10);
      return binaryval;
   }
   /// <summary>
   /// Hex2s the octal.
   /// </summary>
   /// <param name="hexvalue">The hexvalue.</param>
   /// <returns></returns>
   public static string hex2Octal(string hexvalue)
   {
      string binaryval = "";
      binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 8);
      return binaryval;
   }
}

Again , the Convert.ToString method and Convert.ToInt method was used to achieve this function .

Simple Isn’t it ?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...