27+ C# Decimal to Binary Converter Examples

This post contains a total of 27+ C Sharp Decimal to Binary Converter Examples with Source Code. All these Decimal to binary converters are made using C Sharp Programming language.

You can use the source code of these examples with credits to the original owner.

Related Posts

C Sharp Decimal to Binary Converter Examples

1. By Jasper Diongco

Made by Jasper Diongco. Enter a decimal number to get an binary output. Source

Decimal: 1
Binary: 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
           //decimal to binary
           
           int dec = int.Parse(Console.ReadLine());//Enter input
           string binary= "";
           Console.WriteLine("Decimal: "+dec);
           while(dec != 0)
           {
               int remainder = dec % 2;
               dec /= 2;
               binary += remainder;
           }
           Console.Write("Binary: ");
           for(int i = binary.Length - 1; i>= 0;i--)
           Console.Write(binary[i]);
        }
    }
}

2. By Nurlan Aliyev

Made by Nurlan Aliyev. Basic C# Decimal to Binary Program. Source

2 in binary is 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            /*Program that converts decimal to binary easy method by Nurlan Aliyev*/
            int N = int.Parse(Console.ReadLine());
            string binary = Convert.ToString(N,2);
            
            Console.WriteLine("{0} in binary is {1}",N,binary);
        }
    }
}

3. By DxrkSxul

Made by DxrkSxul. Source

3
11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            //Decimal to binary.
            string b = "";
            for (int d = Convert.ToInt32(Console.ReadLine()); d > 0;d = d / 2){
                b = (d % 2) + b;
            }
            Console.Write(b);
        }
    }
}

4. By Asgar Ali

Made by Asgar Ali. Source

4 in binary is 100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
           int dec = 0;
    if(int.TryParse(Console.ReadLine(),out dec))
    {
     string bin = Convert.ToString(dec,2);
     string hex = Convert.ToString(dec,16);
     Console.WriteLine("{0} in binary is " + bin,dec);
    Console.WriteLine("{0} in Hexadecimal is " + hex,dec);
    }
    else Console.WriteLine("Please input a number");
        }
    }
}

5. By WildGeese

Made by WildGeese. Source

5
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
    
       static  void Main(string[] args)
        {
        
        int x;
       x=int.Parse(Console.ReadLine());
           binary(x);
        }
        public static  void binary(int x)
        {
           if(x>0)
           {
              binary(x/2);
              Console.Write(x%2);
           }
        }
    }
}

6. By AVg

Made by AVg. Enter any 64-bit based integer ( UP TO 9,223,372,036,854,775,808 !) and you’ll get it in binary. Source

Here is the binary result of: 6

110        <--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        try {
            long number =
            Convert.ToInt64(
                Console.ReadLine()
            );
        
            long backHold = number;
            
            String result = String.Empty;
            
            while (number != 0) {
                if (number % 2 == 0)
                result += "0";
                else result += "1";
                number /= 2;
            }
        
            Char[] reverse =result.ToCharArray();
            Array.Reverse(reverse);
            
            Console.Write(
            "Decimal To Binary V 1.0 | " 
            + string.Format("{0:hh:mm}", DateTime.Now) +"\n" +
            "--------------------------------\n" +
                "Here is the binary result of: " +
            backHold.ToString() + "\n\n" +
            new string(reverse) + "        <--\n\n" +
            "You May want to UPVOTE!"
            );
            
            }
            catch (Exception err) {
            Console.Write(
                "Dear user please only enter 64-bit based integer ( x < 9000000B )\n" +
                ""
            );
            
        }
        }
    }
}

7. By Saleh

Made by Saleh. Source

Enter a decimal number: 7
  Your binary number is 0111.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize the variables.
            int decNum, quotient;
            string remaining, binary;
            remaining = ""; binary = "";
            
            // Write the initial operation.
            Console.Write("Enter a decimal number: ");
              // Read a decimal number;
            decNum = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(decNum);
            
            // Write the split operation.
            while (decNum >= 1) // Create a while loop.
            {
                quotient = decNum / 2;
                remaining += (decNum % 2).ToString();
                decNum = quotient;
            } // Creat a for loop.
            for (int i = remaining.Length - 1; i >= 0; i--)
            {
                binary += remaining[i];
            }
            
            //  After splitting, It's time to print 
            // the binary number on the output.
            if (binary.Length >= 4)
                Console.WriteLine("  Your binary number" +
                " is {0}.", binary);
            else if (binary.Length <= 3 &&
                            binary.Length >= 2)
                Console.WriteLine("  Your binary number" +
                " is 0{0}.", binary);
            else if (binary.Length == 1)
                Console.WriteLine("  Your binary number" +
                " is 00{0}.", binary);
                
           }
    }
}

8. By Rabee Abbas

Made by Rabee Abbas. Source

enter an integer number 8
Decimal Number : 8
Binary Number : 1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            // user input 
            Console.WriteLine("enter an integer number");
            int number = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Decimal Number : {0}",number);
            
            // a string builder used to hold the binary value of the number
            StringBuilder builder = new StringBuilder();
            
            // Convert decimal to binary 
            while (number >0)
            {
                builder.Insert(0,number%2);
                number=(number-number%2)/2;
            }
            
            // output 
            Console.WriteLine("Binary Number : {0}",builder.ToString());
        }
    }
}

9. By CoderX

Made by CoderX. Source

Decimal:9
Binary:1001
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
      int d = int.Parse(Console.ReadLine());
      string bin = Convert.ToString(d,2);
      string hex = d.ToString("X");
      Console.WriteLine("Decimal:{0}",d);
      Console.WriteLine("Binary:{0}",bin);
      Console.WriteLine("Hexadecimal:{0}",hex);
        }
    }
}

10. By Piotr Tyc

Made by Piotr Tyc. Source

10
1010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        // decimal to binary
      
        static void Main(string[] args)
        {
         int dec = Convert.ToInt32(Console.ReadLine());
         int y;
         string binary = "";
         while (dec > 0)
         {
         y = dec % 2;
         binary = Convert.ToString(y) + binary;
         dec /= 2;
         } 
         Console.WriteLine(binary);
        }
    }
}

11. By NFS101

Made by NFS101. This Is A Program That Will Find The Binary Of Any Decimal Number, Input A Integer In The User Input Box e.g, 10. Source

11
Binary Of 11 is 1011
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
	class Program
	{
		static void toBinary(int a)
		{
		    if(a == 0)
		    {
		        return;
		    }
		    else
		    {
		        toBinary(a / 2);
		        Console.Write(a % 2);
		    }
		}
		
		static void Main(string[] args)
		{
			int input = Convert.ToInt32(Console.ReadLine());
			Console.Write("Binary Of " + input + " is ");
			toBinary(input);
		}
	}
}

12. By Skayo

Made by Skayo. Source

12 -> 1100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int dec = Convert.ToInt32(Console.ReadLine());
            int currDiv = dec;
            string binaryNum = "";
            while(currDiv != 1){
               binaryNum = Convert.ToString(currDiv % 2) + binaryNum;
               currDiv = currDiv / 2;
            }
            binaryNum = Convert.ToString(currDiv % 2) + binaryNum;
            Console.WriteLine("{0} -> {1}",dec,binaryNum);
        }
    }
}

13. By Alex Aramyan

Made by Alex Aramyan. Source

13
1101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		   long n = Convert.ToInt64(Console.ReadLine());
			Console.WriteLine(System.Convert.ToString(n,2));
		}
	}
}

14. By ondra pokondra

Made by ondra pokondra. Source

14
1110
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
       static int ReadNumber()
       {
          return int.Parse(Console.ReadLine());
       }
        static void Main(string[] args)
        {
          char bit;
          int N = ReadNumber();
          string digit = "";
          
          while(N != 0)
          {
            bit =(char)(48+N%2);
            digit= bit+digit; 
            N = N/2;
          }
          Console.WriteLine(digit);
          
        }
    }
}

15. By Odumodu Okwudili Joshua

Made by Odumodu Okwudili Joshua. Source

15
1111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
          int dec = Convert.ToInt32(Console.ReadLine());
          string rslt = Convert.ToString(dec, 2);
          Console.WriteLine(rslt);
        }
    }
}

16. By Marfik Em

Made by Marfik Em. Simple Program to Convert a Decimal number to Binary. Source

(16) in decimal = (10000) in binary
using System;
using static System.Console;


namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int input = int.Parse(ReadLine());
WriteLine("({0}) in decimal = ({1}) in binary", input, Convert.ToString(input, 2));
}
}
}

17. By CyberScythe

Made by CyberScythe. Enter the number you want to be converted to Binary, Must be smaller than 19 digits. Source

17 = 10001 in Binary/Base2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DecimalToBinary 
{
    class Program
    {
        static void Main(string[] args)
        {
            decimalToBinary();
        }
        
        
static void decimalToBinary(){
        
string decimalInput;
string output;
decimalInput = Console.ReadLine();
int counter = 0;
UInt64 decimalInputAsInt;
List<UInt64> remainders = new List<UInt64>();
List<UInt64> temp = new List<UInt64>();

if (decimalInput.All(Char.IsDigit) && decimalInput != "" && !decimalInput.Contains(" ")){

if (decimalInput.Length <= 19){

decimalInputAsInt = Convert.ToUInt64(decimalInput);

while (decimalInputAsInt > 0){
                        remainders.Add(decimalInputAsInt % 2) ;
decimalInputAsInt /= 2;
counter++;
                             }
                                        
remainders.Reverse();
output = string.Join("", remainders);
Console.WriteLine("\n" + decimalInput + " = " + output + " in Binary/Base2 \n");
                               }
else{Console.WriteLine("Number must be smaller than 19 digits");}
                                   }
else{Console.WriteLine("Input must be a whole number with no spaces");}
                            }
    }
}

18. By Mehboob Shah

Made by Mehboob Shah. Source

Enter decimal no. to convert : 
18
binary equivalent : 
10010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        { int[] rem=new int [10];
        Console.WriteLine("Enter decimal no. to convert : ");
            int a=int.Parse(Console.ReadLine());
            Console.WriteLine(a);
            int i;
            for(i=0;a>0;i++){
                rem[i]=a%2;
                a/=2;
            } 
            Console.WriteLine("binary equivalent : ");
            for(i=i-1;i>=0;i--){
                Console.Write(rem[i]);
            }
            
        }
    }
}

19. By ilya.iz

Made by ilya.iz. Source

Your number is: 19
Binary: 10011
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


// my C# Converter "Decimal-->Binary"

namespace SoloLearn
{
    class Program
    {   
        static void bin(int x)
        {
            string binary = Convert.ToString(x, 2);
            Console.WriteLine("Binary: "+binary);
        }
        
        static void Main(string[] args)
        {
           int  bn = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine("Your number is: "+bn);
           bin(bn); 
        }
    }
}

20. By Reee

Made by Reee. Source

input a decimal number

20

Here is your binary 

10100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        
        	Console.WriteLine("input a decimal number\n");
        	int digi=Convert.ToInt16(Console.ReadLine());
        
        	int basex=2;
        	int rem=0;
        	string equals="";
        	
        	while(digi!=0)
        	{
        		rem=digi%basex;
        		
        		digi=digi/basex;
        	
        	        equals=equals.Insert(equals.Length,rem.ToString());
        	}
        	
        	
           char[]arr=equals.ToCharArray();
           Array.Reverse(arr);
           Console.WriteLine("Here is your binary \n");
           for(int i =0; i<arr.Length; i++)
           {
           	Console.Write(arr.GetValue(i));
           	
           }
           
            
            
        }
    }
}

21. By MichaΕ‚ Zawitaj

Made by MichaΕ‚ Zawitaj. Source

21
Decimal to Binary:  10101
using System;

namespace SoloLearn
{
    class DecimalToBinary 
    {
        static void Main(string[] args)
        {
            int y = int.Parse(Console.ReadLine());
            int x;
            string z = string.Empty;
            while (y > 0)
            {
                x = y % 2;
                y /= 2;
                z = x.ToString() + z;
            }
            Console.WriteLine("Decimal to Binary:  {0}",z);
        }
    }
}

22. By Victor Dantas

Made by Victor Dantas. Source

22
10110
using System;
using System.Text;

class Program
{
  static void Main()
  {
    int input = int.Parse(Console.ReadLine());
    var res = new StringBuilder();
    int rem = 0;
    do
    {
      rem = input % 2;
      input /= 2;
      res.Append(rem);
      if (input <= 0)
        break;
    } while (true);
    string binary = res.ToString();
    for (int i = binary.Length - 1; i >= 0; i--)
      Console.Write(binary[i]);
  }
}

23. By Rex

Made by Rex. Source

Enter a Number : 23
The Binary format for given number is 10111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
			int num;
        Console.Write("Enter a Number : ");
        num = int.Parse(Console.ReadLine());
        int quot;
        string rem = "";
        while (num >= 1)
        {
            quot = num / 2;
            rem += (num % 2).ToString();
            num = quot;
        }
        string bin = "";
        for (int i = rem.Length - 1; i >= 0; i--)
        {
            bin = bin + rem[i];
        }
        Console.WriteLine("The Binary format for given number is {0}", bin);
        Console.Read();
		}
	}
}

24. By BonPon

Made by BonPon. Source

24
11000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static string toBinary(int n)
        {
            if (n == 0)
            {
               return "0";            
            }
            
            string binary = "";
            int rem;
            
            
            while (n > 0)
            {
              rem = n % 2;
              n = n / 2;
              binary = rem + binary;
            }
            return binary;
        }
         static void Main(string[] args)
        {
   string numuc = Console.ReadLine();
   int num = Convert.ToInt32(numuc);
   Console.WriteLine(toBinary(num));
        }
    }
}

25. By Sololearn

Made by Sololearn. Source

156
10011100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/* A binary number is made up of elements called bits where each bit can be 1 or 0 */
namespace SoloLearn
{
    class Program
    {
        static string toBinary(int n)
        {
            if (n == 0)
            {
                return "0";
            }
    
            string binary = "";
            while (n > 0)
            {
                // The % (modulus) operator returns the remainder of the division
                int rem = n % 2;
                // add the result (0 or 1)
                binary = rem + binary;
                // divide the number by 2
                n = n / 2;
            }
    
            return binary;
        }
        
        static void Main(string[] args)
        { 
            //sample number
            int number = 156;
            
            Console.WriteLine(toBinary(number));
        }
    }
}

26. By Muralitharan K

Made by Muralitharan K. Simple Decimal to Binary Converter Program. Source

26
11010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        int n,i;
  n=Convert.ToInt32(Console.ReadLine()); 
              int[] arr=new int[10];
              for( i=0;n>0;i++)
              {
                  arr[i]=n%2;
                  n=n/2;
                  
              }
              for( i=i-1;i>=0;i--)
              {
                 Console.Write(arr[i]); 
              }
          
        }
    }
}

27. By Alessio

Made by Alessio. Source

255
11111111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
        
   int value = 255; 
 string binary = Convert.ToString(value, 2);
         Console.Write(binary);
        }
    }
}

28. By Felix

Made by Felix. Simple decimal to binary calculator with no Exceptional handler. Source

28
binary: 11100
using System;

public class Test
{
	public static void Main()
	{
		CalcBin();
		Console.ReadLine();
	}
	
	public static string Ausgabe;
	
	public static void CalcBin()
	{
  int input = Int32. Parse(Console.ReadLine());
	int x;
	
		do 
		{
			x = input%2;
			Ausgabe = (x.ToString())+Ausgabe;
			input = input/2;
			}
			while (input > 0);

  Console.WriteLine("binary: " + Ausgabe);
 }
 }