0% found this document useful (0 votes)
13 views1 page

Decimal To Binary

The document contains a C# method that converts a decimal number to binary by recursively taking the number modulo 2 and dividing by 2 until the number is 0, building the binary string in reverse order.

Uploaded by

sovetmansur228
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Decimal To Binary

The document contains a C# method that converts a decimal number to binary by recursively taking the number modulo 2 and dividing by 2 until the number is 0, building the binary string in reverse order.

Uploaded by

sovetmansur228
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System.

Numerics;

Int64 userNumber;

int two = 2;

Int64 DecimalToBinary(Int64 number)


{
string binaryNumber;
Int64 test;

if (number == 0)
{
return 0;
}

test = number % two;


number = number / two;

binaryNumber = "" + DecimalToBinary(number) + test;


return Convert.ToInt64(binaryNumber);
}

Console.Write("Number = ");
userNumber = Convert.ToInt64(Console.ReadLine());

Console.WriteLine(DecimalToBinary(userNumber));

You might also like