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:
- Maximum decimal equivalent possible among all connected components of a Binary Valued Graph
- Decimal representation of given binary string is divisible by 10 or not
- Decimal representation of given binary string is divisible by 5 or not
- Check whether the binary equivalent of a number ends with "001" or not
- Check whether the binary equivalent of a number ends with given string or not
- Decimal Equivalent of Gray Code and its Inverse
- Maximize the decimal equivalent by flipping only a contiguous set of 0s
- Binary representation of next number
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Largest number with binary representation is m 1's and m-1 0's
- Sum of digits with even number of 1's in their binary representation
- Binary representation of previous number
- 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
- Prime Number of Set Bits in Binary Representation | Set 2
- Check if binary representation of a number is palindrome
- 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
- Number of mismatching bits in the binary representation of two integers
- C program to count zeros and ones 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 email@example.com. 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.