943,866 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 12794
  • C# RSS
Dec 22nd, 2008
0

binary to decimal

Expand Post »
I want to know how to make a program to convert from binary to decimal and from decimal to binary
Reputation Points: 10
Solved Threads: 0
Light Poster
Egypt Pharaoh is offline Offline
40 posts
since Dec 2008
Dec 22nd, 2008
0

Re: binary to decimal

In console apllication please
Reputation Points: 10
Solved Threads: 0
Light Poster
Egypt Pharaoh is offline Offline
40 posts
since Dec 2008
Dec 22nd, 2008
0

Re: binary to decimal

Google binary to decimal in C# you may find what you need.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Dec 22nd, 2008
0

Re: binary to decimal

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!!
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Dec 22nd, 2008
0

Re: binary to decimal

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 23rd, 2008
0

Re: binary to decimal

.NET even has a built-in function to do the conversation. Some basic research would tell you the answer
Reputation Points: 11
Solved Threads: 9
Junior Poster in Training
vckicks is offline Offline
58 posts
since Jun 2008
Dec 23rd, 2008
0

Re: binary to decimal

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...

C# Syntax (Toggle Plain Text)
  1. using System;
  2.  
  3. class Program{
  4.  
  5. static void Main(string[] args){
  6.  
  7. try{
  8.  
  9. int i = ToDecimal(args[0]);
  10. Console.WriteLine("\n{0} converted to Decimal is {1}",args[0],i);
  11.  
  12. }catch(Exception e){
  13.  
  14. Console.WriteLine("\n{0}\n",e.Message);
  15.  
  16. }
  17.  
  18. }//end Main
  19.  
  20.  
  21. public static int ToDecimal(string bin)
  22. {
  23. long l = Convert.ToInt64(bin,2);
  24. int i = (int)l;
  25. return i;
  26. }
  27.  
  28.  
  29. }//end class Program
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Oct 6th, 2011
0
Re: binary to decimal
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);
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
megabuild7 is offline Offline
4 posts
since Oct 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: single Datagridview - show/insert/update/delete [Multiple tables]
Next Thread in C# Forum Timeline: C# Properties





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC