954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

binary to decimal

I want to know how to make a program to convert from binary to decimal and from decimal to binary

Egypt Pharaoh
Light Poster
40 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

In console apllication please

Egypt Pharaoh
Light Poster
40 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Google binary to decimal in C# you may find what you need.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Try first to write your solution in a draft, think how to code it, all of us know how to convert it theoretically, which means you won't pay a lot to think, and to code; it's for your interest to do it yourself, some lines of codes won't help you as they are not written by you!!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

You have a huge number of ways to do it.

You could either tackle it as a human would, or, you look though the helpfile and see if theres a prebuilt way to do it.

Either way, get some ideas on paper, try and code it, and then when you have something... We'll help.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

.NET even has a built-in function to do the conversation. Some basic research would tell you the answer

vckicks
Junior Poster in Training
58 posts since Jun 2008
Reputation Points: 11
Solved Threads: 9
 

From Decimal to Binary..
using System;

class Program{

static void Main(string[] args){

try{

int i = (int)Convert.ToInt64(args[0]);
Console.WriteLine("\n{0} converted to Binary is {1}\n",i,ToBinary(i));

}catch(Exception e){

Console.WriteLine("\n{0}\n",e.Message);

}

}//end Main


public static string ToBinary(Int64 Decimal)
{
// Declare a few variables we're going to need
Int64 BinaryHolder;
char[] BinaryArray;
string BinaryResult = "";

while (Decimal > 0)
{
BinaryHolder = Decimal % 2;
BinaryResult += BinaryHolder;
Decimal = Decimal / 2;
}

// The algoritm gives us the binary number in reverse order (mirrored)
// We store it in an array so that we can reverse it back to normal
BinaryArray = BinaryResult.ToCharArray();
Array.Reverse(BinaryArray);
BinaryResult = new string(BinaryArray);

return BinaryResult;
}


}//end class Program

From Binary to Decimal...

using System;

class Program{

   static void Main(string[] args){

      try{
        
         int i = ToDecimal(args[0]);
         Console.WriteLine("\n{0} converted to Decimal is {1}",args[0],i);
      
      }catch(Exception e){
        
         Console.WriteLine("\n{0}\n",e.Message);
 
      }

   }//end Main


                public static int ToDecimal(string bin)
  {
                    long l = Convert.ToInt64(bin,2);
                    int i = (int)l;
                    return i;
  }


}//end class Program
Aneesh_Argent
Junior Poster
104 posts since Dec 2008
Reputation Points: 16
Solved Threads: 18
 

binary to decimal code -new-


private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
string sayii = textBox1.Text.Substring(0, textBox1.Text.Length);
uint[] sayicc = new uint[textBox1.Text.Length];

for (int i = 0; i < textBox1.Text.Length; i++)
{
sayicc[i] = Convert.ToUInt32(sayii[i] - 48);

}

uint[] dizi2 = new uint[textBox1.Text.Length];
uint bit = 1;

for (int j = 0; j < textBox1.Text.Length; j++)
{
dizi2[j] = bit;
bit *= 2;
}
Array.Reverse(dizi2);
uint deger = 0;
for (int i = 0; i <= dizi2.Length - 1; i++)
{
dizi2[i] *= sayicc[i];

if (sayicc[i] == 1)
{
deger += dizi2[i];
}
}
textBox2.Text = " " + deger.ToString();
}
else
{
MessageBox.Show("Deger girilecek alan boş.", "HATA!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

megabuild7
Newbie Poster
4 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You