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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Decimal to octal conversion with minimum use of arithmetic operators
- Program for Decimal to Binary Conversion
- Program for Binary To Decimal Conversion
- Program for Octal to Decimal Conversion
- Program for decimal to hexadecimal conversion
- Program for Decimal to Octal Conversion
- How to sum two integers without using arithmetic operators in C/C++?
- Subtract 1 without arithmetic operators
- Add two numbers without using arithmetic operators
- Convert Binary fraction to Decimal
- Recursive Program for Binary to Decimal
- Decimal to binary number using recursion
- Binary to decimal and vice-versa in python
- Decimal representation of given binary string is divisible by 20 or not
- Decimal to Binary using recursion and without using power operator
Improved By : Mithun Kumar