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

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

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

public static class BinaryConverter
{
   /// <summary>
   /// Binaries to decimal.
   /// </summary>
   /// <param name="bin">The bin.</param>
   /// <returns></returns>
   public static Int64 BinaryToDecimal(string bin)
   {
      long l = Convert.ToInt64(bin, 2);
      int i = (int)l;
      return i;
   }
   /// <summary>
   /// Binaries to octal.
   /// </summary>
   /// <param name="bin">The bin.</param>
   /// <returns></returns>
   public static Int64 BinaryToOctal(string bin)
   {
      Int64 Deci = BinaryConverter.BinaryToDecimal(bin);
      return DecimalConverter.DecimalToOctal(Deci);
   }
   /// <summary>
   /// Binaries to hexa.
   /// </summary>
   /// <param name="bin">The bin.</param>
   /// <returns></returns>
   public static string BinaryToHexa(string bin)
   {
      Int64 Deci = BinaryConverter.BinaryToDecimal(bin);
      return DecimalConverter.DecimalToHex(Deci);
   }
}

DecimalConverter is a static class that was described in my previous blog post . The Convert method is again used to convert from Binary to decimal .

Please do share with me of any other simple logic to convert Binary Number to other formats 🙂

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

No Responses

  1. How to convert Binary Number to Decimal ,... | .NET and C# | Syngu September 1, 2011 Reply
  2. How to convert Binary Number to Decimal , HexaDecimal and Octal Number using C# | ProgramInDotnet October 23, 2011 Reply
  3. How to convert Octal Number to Decimal , HexaDecimal and Binary Number using C# | ProgramInDotnet October 23, 2011 Reply

Leave a Reply


x

Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...