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