C# Program to Find Binary Equivalent of an Integer using Recursion Last Updated : 18 Oct, 2021 Comments Improve Suggest changes 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 C# Program to Find Binary Equivalent of an Integer using Recursion 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 JavaScript Program to Convert Decimal to Binary Using Recursion JavaScript allows us to convert decimal numbers to their binary equivalents using recursion, offering two distinct approaches. Through recursive division and concatenation, the first method constructs the binary representation directly. The second method leverages a string and recursion, providing a 2 min read Java Program to Convert a Decimal Number to Binary Number using Stacks Java is high level, compiled as well as interpreted programming language. Stack is an abstract data type used in most of the programming languages and can be implemented using arrays or linked list. Stack data structure follows the principle of LIFO (Last In First Out) . Stack allows push, pop, peek 3 min read Java Program to Convert a Decimal Number to Binary Number using Arrays as Stacks Given an Integer number convert into Binary Number using arrays as a stack. Example: Input : 10 Output: 1010 Input : 16 Output: 10000 Approach: Divide the number by 2 and store the remainder of the number in the array.Divide the number by 2.Repeat the process until the number becomes zero.Print the 1 min read Python program to print the binary value of the numbers from 1 to N Given a positive number N, the task here is to print the binary value of numbers from 1 to N. For this purpose various approaches can be used. The binary representation of a number is its equivalent value using 1 and 0 only. Example for k = 15, binary value is 1 1 1 1 WORKING FOR METHOD 1Method 1: U 2 min read Like