C# Program to Find Binary Equivalent of an Integer using Recursion Last Updated : 18 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an integer number, now we convert the given integer number into a binary number using recursion. Recursion is a method in which a function calls itself directly or indirectly and such type of function is known as a recursive function. It solves the problem very efficiently like we find the binary equivalent of an integer. Examples: Input : 10 Output: 1010 Input : 11 Output: 1011Approach: To display the binary equivalent of an integer we use the following steps: If condition is used to check if the given value is not equal to zero.If the given condition is true then perform the modulus of the val by 2, then add the modulus result to 10 and then multiply the value of the result with the value of decimaltobinary() function.Now repeat step 2 until the value of val variable is greater than zero.Print the array in reverse order now.And if the condition is false then it will execute the else section, i.e., return 0The below image can help you better understand the approach. Let us considered the integer number is 10. Now we find the binary equivalent of 10 so, 10 % 2 + 10 * (10 / 2) % 2 will return 05 % 2 + 10 * (5 / 2) % 2 will return 12 % 2 + 10 * (2 / 2) % 2 will return 01 % 2 + 10 * (1 / 2) % 2 will return 1So the final result is 1010. Example 1: C# // C# program to display the binary equivalent // of an integer using System; class GFG{ // Driver code public static void Main(string[] args) { // Input int num = 15; decimaltobinary(num); } // Function to display the binary equivalent // of an integer public static int decimaltobinary(int val) { int binary; if (val != 0) { binary = (val % 2) + 10 * decimaltobinary(val / 2); Console.Write(binary); return 0; } else { return 0; } } } Output1111Example 2: C# // C# program to display the binary equivalent // of an integer using System; class GFG{ // Function to display the binary equivalent // of an integer public static int decimaltobinary(int val) { int binary; if (val != 0) { binary = (val % 2) + 10 * decimaltobinary(val / 2); Console.Write(binary); return 0; } else { return 0; } } // Driver code public static void Main(string[] args) { int num; // Reading input from user Console.Write("Hi! Enter the number:"); num = int.Parse(Console.ReadLine()); decimaltobinary(num); } } Output: Hi! Enter the number:10 1010 Comment More infoAdvertise with us Next Article Find the Number Using Bitwise Questions I P pulamolusaimohan Follow Improve Article Tags : C# CSharp LINQ CSharp-programs Similar Reads C# Program for Count set bits in an integer Write an efficient program to count number of 1s in binary representation of an integer. Examples :Input : n = 6Output : 2Binary representation of 6 is 110 and has 2 set bitsInput : n = 13Output : 3Binary representation of 11 is 1101 and has 3 set bits1. Simple Method Loop through all bits in an int 2 min read Find the Number Using Bitwise Questions I Given a task to find a number n. There is a pre-defined API int commonSetBits(int val) that returns the number of bits where both n and val have a value of 1 in the corresponding position of their binary representation. In other words, it returns the number of set bits in the bitwise AND (&) ope 4 min read Counting Set bit in C In C programming, counting set bits is the process of determining the number of bits that are set to 1 in a binary number. This operation is useful in various applications including network programming, error detection, and cryptography.In this article, we will learn how to count the number of set b 4 min read Number System Conversion in C Number system conversion is a fundamental concept in computer science and programming. It involves changing the representation of a number from one base to another, such as converting a decimal number to binary or a hexadecimal number to binary.In this article, we will create a console program in th 8 min read C# Program to Convert a Binary String to an Integer Given an binary string as input, we need to write a program to convert the binary string into equivalent integer. To convert an binary string to integer, we have to use Convert.ToInt32(String, Base/Int32) function to convert the values. The base of the binary is 2. Syntax: Convert.ToInt32(String, Ba 2 min read C Program to Find Sum of Natural Numbers using Recursion Natural numbers include all positive integers from 1 to infinity. There are multiple methods to find the sum of natural numbers and here, we will see how to find the sum of natural numbers using recursion. Example Input : 5Output : 15Explanation : 1 + 2 + 3 + 4 + 5 = 15 Input : 10Output : 55Explanat 2 min read Like