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

## 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;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
//decimal to binary

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;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
/*Program that converts decimal to binary easy method by Nurlan Aliyev*/
string binary = Convert.ToString(N,2);

Console.WriteLine("{0} in binary is {1}",N,binary);
}
}
}``````

### 3. By DxrkSxul

```3
11```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

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

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int dec = 0;
{
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);
}
}
}
}
``````

### 5. By WildGeese

```5
101```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoloLearn
{
class Program
{

static  void Main(string[] args)
{

int x;
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;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
try {
long number =
Convert.ToInt64(
);

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

```Enter a decimal number: 7
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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: ");
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)
" is {0}.", binary);
else if (binary.Length <= 3 &&
binary.Length >= 2)
" is 0{0}.", binary);
else if (binary.Length == 1)
" is 00{0}.", binary);

}
}
}``````

### 8. By Rabee Abbas

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

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
// user input
Console.WriteLine("enter an integer number");
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

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

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

### 10. By Piotr Tyc

```10
1010```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoloLearn
{
class Program
{
// decimal to binary

static void Main(string[] args)
{
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;

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)
{
Console.Write("Binary Of " + input + " is ");
toBinary(input);
}
}
}``````

### 12. By Skayo

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

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
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

```13
1101```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

### 14. By ondra pokondra

```14
1110```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoloLearn
{
class Program
{
{
}
static void Main(string[] args)
{
char bit;
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;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
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)
{
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;

namespace DecimalToBinary
{
class Program
{
static void Main(string[] args)
{
decimalToBinary();
}

static void decimalToBinary(){

string decimalInput;
string output;
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){
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

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

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{ int[] rem=new int [10];
Console.WriteLine("Enter decimal no. to convert : ");
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

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

// 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)
{
bin(bn);
}
}
}``````

### 20. By Reee

```input a decimal number

20

10100```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("input a decimal number\n");

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);
for(int i =0; i<arr.Length; i++)
{
Console.Write(arr.GetValue(i));

}

}
}
}``````

### 21. By Michał Zawitaj

```21
Decimal to Binary:  10101```
``````using System;

namespace SoloLearn
{
class DecimalToBinary
{
static void Main(string[] args)
{
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

```22
10110```
``````using System;
using System.Text;

class Program
{
static void Main()
{
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

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

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int num;
Console.Write("Enter a Number : ");
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);
}
}
}``````

### 24. By BonPon

```24
11000```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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)
{
int num = Convert.ToInt32(numuc);
Console.WriteLine(toBinary(num));
}
}
}``````

### 25. By Sololearn

```156
10011100```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/* 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;

namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int n,i;
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

```255
11111111```
``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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();
}

public static string Ausgabe;

public static void CalcBin()
{