Skip to content

Instantly share code, notes, and snippets.

@bigworld12
Created March 31, 2017 21:37
Show Gist options
  • Save bigworld12/73963ca330073db1652594d209b6b1ac to your computer and use it in GitHub Desktop.
Save bigworld12/73963ca330073db1652594d209b6b1ac to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());
Console.WriteLine(deciToBinary(num));
Console.ReadKey();
}
public static int deciToBinary(int num, int multiplier = 1)
{
if (num == 0)
{
return 0;
}
else
{
//recursion
return deciToBinary(num / 2, multiplier * 10) + (num % 2) * multiplier;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment