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
- Program for Binary To Decimal Conversion
- Program for Decimal to Binary Conversion
- Program for Decimal to Octal Conversion
- Program for Octal to Decimal Conversion
- Decimal to binary number using recursion
- Binary to decimal and vice-versa in python
- Decimal representation of given binary string is divisible by 10 or not
- Decimal representation of given binary string is divisible by 20 or not
- Python program to convert decimal to binary number
- Recursive Program for Binary to Decimal
- Maximum decimal equivalent possible among all connected components of a Binary Valued Graph
- BCD or Binary Coded Decimal
- Type Conversion in Python
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Convert from any base to decimal and vice versa
- Converting Roman Numerals to Decimal lying between 1 to 3999
- Quickly convert Decimal to other bases in Python
- Program for Hexadecimal to Decimal
- Convert all substrings of length 'k' from base 'b' to decimal
Improved By : Mithun Kumar