binary to decimal

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 17
Reputation: Egypt Pharaoh is an unknown quantity at this point 
Solved Threads: 0
Egypt Pharaoh Egypt Pharaoh is offline Offline
Newbie Poster

binary to decimal

 
0
  #1
Dec 22nd, 2008
I want to know how to make a program to convert from binary to decimal and from decimal to binary
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 17
Reputation: Egypt Pharaoh is an unknown quantity at this point 
Solved Threads: 0
Egypt Pharaoh Egypt Pharaoh is offline Offline
Newbie Poster

Re: binary to decimal

 
0
  #2
Dec 22nd, 2008
In console apllication please
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 282
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: binary to decimal

 
0
  #3
Dec 22nd, 2008
Google binary to decimal in C# you may find what you need.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: binary to decimal

 
0
  #4
Dec 22nd, 2008
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!!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: binary to decimal

 
0
  #5
Dec 22nd, 2008
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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 58
Reputation: vckicks is an unknown quantity at this point 
Solved Threads: 9
vckicks vckicks is offline Offline
Junior Poster in Training

Re: binary to decimal

 
0
  #6
Dec 23rd, 2008
.NET even has a built-in function to do the conversation. Some basic research would tell you the answer
Visual C# Kicks - Free C# code resources and articles.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: binary to decimal

 
0
  #7
Dec 23rd, 2008
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...

  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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC