Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ Given a number N. Print the result of doing the following operation on N : - Comvert N to its binary representation. -
in c++
Given a number N. Print the result of doing the following operation on N : - Comvert N to its binary representation. - Count number of ones in the above binary representation. - Print the equivalent decimal number that its binary representation has only the number of ones that were counted above. For example: (10)decimat=(1010)bimary has 2 ones " 11", after converting " 11" to decimal number it will become 3. Input First line contains a number T(1T10) number of test cases. Next T lines will contain a number N(1N2311). Output For each test case print a single line contains the answer according to the required above. Note To convert decimal number to binary: A decimal integer can be comverted to binary by dividing it by 2. Take the quotient, and keep dividing it by 2, until you reach zero. Each time you perform this division, take note of the remainder, Now reverse the remainders list, and you get the number in binary form Example to convert 29 to binary Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started