Find the binary equivalent of the given non-negative number n without using arithmetic operators.
Input : n = 10 Output : 1010 Input : n = 38 Output : 100110
Note that + in below algorithm/program is used for concatenation purpose.
decToBin(n) if n == 0 return "0" Declare bin = "" Declare ch while n > 0 if (n & 1) == 0 ch = '0' else ch = '1' bin = ch + bin n = n >> 1 return bin
Time complexity: O(num), where num is the number of bits in the binary representation of n.
This article is contributed by Ayush Jauhari. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Decimal to octal conversion with minimum use of arithmetic operators
- Add two numbers without using arithmetic operators
- How to sum two integers without using arithmetic operators in C/C++?
- Subtract 1 without arithmetic operators
- Program for Binary To Decimal Conversion
- Program for Decimal to Binary Conversion
- Decimal to Binary using recursion and without using power operator
- Program for decimal to hexadecimal conversion
- Program for Octal to Decimal Conversion
- Program for Decimal to Octal Conversion
- Convert Decimal To Hexa-Decimal including negative numbers
- Gray to Binary and Binary to Gray conversion
- Print all substring of a number without any conversion
- Multiply two integers without using multiplication, division and bitwise operators, and no loops
- Write you own Power without using multiplication(*) and division(/) operators
- Check if a number is multiple of 5 without using / and % operators
- C++ program to divide a number by 3 without using *, / , +, -, % operators
- Largest of two distinct numbers without using any conditional statements or operators
- Find Quotient and Remainder of two integer without using division operators
- Removing a number from array without changing its arithmetic mean
Improved By : Mithun Kumar