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.
- Decimal to octal conversion with minimum use of arithmetic operators
- Program for Binary To Decimal Conversion
- Program for Decimal to Binary Conversion
- Program for octal to decimal conversion
- Program for decimal to hexadecimal conversion
- Program for decimal to octal conversion
- Add two numbers without using arithmetic operators
- How to sum two integers without using arithmetic operators in C/C++?
- Subtract 1 without arithmetic operators
- Convert Binary fraction to Decimal
- Decimal to binary number using recursion
- Recursive Program for Binary to Decimal
- Decimal representation of given binary string is divisible by 20 or not
- Decimal representation of given binary string is divisible by 10 or not
- Binary to decimal and vice-versa in python
Improved By : Mithun Kumar