Given a number N. The task is to find the sum of the decimal equivalent of all the pairs formed from the binary representation of the given number.
Input: N = 4
Binary equivalent of 4 is 100.
All possible pairs are 10, 10, 00 and their decimal equivalent are 2, 2, 0 respectively.
So, 2 + 2+ 0 = 4
Input: N = 11
All possible pairs are: 10, 11, 11, 01, 01, 11
Sum = 2 + 3 + 3 + 1 + 1 + 3 = 13
- Find the binary equivalent of N and store it in a vector.
- Run two loops to consider each and every pair formed from the bits of binary equivalent stored in the vector.
- Find the decimal equivalent of all the pairs and add them.
- Return the sum.
Below is the implementation of the above approach:
- Decimal representation of given binary string is divisible by 5 or not
- Decimal representation of given binary string is divisible by 10 or not
- Decimal Equivalent of Gray Code and its Inverse
- Binary representation of next number
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Binary representation of previous number
- Largest number with binary representation is m 1's and m-1 0's
- Next greater number than N with exactly one bit different in binary representation of N
- Prime Number of Set Bits in Binary Representation | Set 1
- Check if binary representation of a number is palindrome
- Prime Number of Set Bits in Binary Representation | Set 2
- Convert decimal fraction to binary number
- Number of mismatching bits in the binary representation of two integers
- Check if binary representation of a given number and its complement are anagram
- Find consecutive 1s of length >= n in binary representation of a number
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.