Given a number N. Print the result of doing the following operation on N: • Convert 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: (10ldecimal" (1010)inary has 2 ones "11", after converting "11" to decimal number it will become 3
Given a number N. Print the result of doing the following operation on N: • Convert 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: (10ldecimal" (1010)inary has 2 ones "11", after converting "11" to decimal number it will become 3
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Write a program in C++
![Given a number N. Print the result of doing the following operation on N:
• Convert 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)decimal = (1010)sinary has 2 ones "11", after converting "1" to decimal number it will
become 3.
Input
First line contains a number T (15T:10) number of test cases.
Next Tlines will contain a number N (15NS21-1).
Ouput
For each test case print a single line contains the answer according to the required above.
Example
Input
3
18
Output
1
Note
To convert decimal number to binary :
A decimal integer can be converted 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
Operation
Result
Remainder
Slep 1
29/2
14
Step 2
14/2
Slep 3
712
3
Slep 4
312
1
Step 5
1/2
for more details visit this https://flaviocapes.com/converting-decimal-to-binary/
To convert from binary to Decimal :
Binary Number - 11101,
Calculating Decimal Equivalent-
Step
Binary Number
Dacimal Number
Siep 1
11101,
((1 x 2) - (1 - 2) + (1 x 2) - 0 x 2") - (1 - 2i»a
Slep 2
11101-
(16 -8-4+0+ 1h
Slep 3
11101-
290
Second Test Case:
(7)decimal = (11)pinary has 3 ones "1", after converting "11" to decimal number it will become 7.
Third Test Case:
(8)decimal = (1000 inary has 1 one "1", after converting "1" to decimal number it will become 1.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F736931cd-57d9-46fd-9fed-204909bebd66%2F91313137-9095-418e-a7e4-4a387ce00255%2Fvcrzs1g_processed.png&w=3840&q=75)
Transcribed Image Text:Given a number N. Print the result of doing the following operation on N:
• Convert 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)decimal = (1010)sinary has 2 ones "11", after converting "1" to decimal number it will
become 3.
Input
First line contains a number T (15T:10) number of test cases.
Next Tlines will contain a number N (15NS21-1).
Ouput
For each test case print a single line contains the answer according to the required above.
Example
Input
3
18
Output
1
Note
To convert decimal number to binary :
A decimal integer can be converted 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
Operation
Result
Remainder
Slep 1
29/2
14
Step 2
14/2
Slep 3
712
3
Slep 4
312
1
Step 5
1/2
for more details visit this https://flaviocapes.com/converting-decimal-to-binary/
To convert from binary to Decimal :
Binary Number - 11101,
Calculating Decimal Equivalent-
Step
Binary Number
Dacimal Number
Siep 1
11101,
((1 x 2) - (1 - 2) + (1 x 2) - 0 x 2") - (1 - 2i»a
Slep 2
11101-
(16 -8-4+0+ 1h
Slep 3
11101-
290
Second Test Case:
(7)decimal = (11)pinary has 3 ones "1", after converting "11" to decimal number it will become 7.
Third Test Case:
(8)decimal = (1000 inary has 1 one "1", after converting "1" to decimal number it will become 1.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education