2. A number in decimal form has digits 0 through 9 and has the interpretation 52431 = 5. 104 +2 103 +4 . 102 + 3 . 101 +

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

2. A number in decimal form has digits 0 through 9 and has the interpretation 52431 = 5. 104 +2 103 +4 . 102 + 3 . 101 +

Post by answerhappygod »

2 A Number In Decimal Form Has Digits 0 Through 9 And Has The Interpretation 52431 5 104 2 103 4 102 3 101 1
2 A Number In Decimal Form Has Digits 0 Through 9 And Has The Interpretation 52431 5 104 2 103 4 102 3 101 1 (391.77 KiB) Viewed 65 times
Please write code in C++
2. A number in decimal form has digits 0 through 9 and has the interpretation 52431 = 5. 104 +2 103 +4 . 102 + 3 . 101 + 1.100 A number in binary form has bits 0, 1 and has the interpretation 101101 = 1.25 +0.24 +1.23 +1.22 +0.21 + 1.20 = To distinguish between numbers in decimal and numbers in binary, we often use 10 and 2 as subscripts, respectively. So, 510 1012 and 4710 = 1011112 Have the first substantial lines of code you write be cout << "Enter a strictly positive integer: " << endl; unsigned int x; cin >> x; if (x == 0) { cout << "This number is not STRICTLY positive." << endl; return 0; } cout << "The binary representation of " «x « " is given by "; and then write more code so that your program converts the decimal number into the cor- responding binary number. The output should look like... Enter a strictly positive integer: 4567 The binary representation of 4567 is given by 1000111010111 Further comments... • submit the solution as hw3 2.cpp • you can assume the user's input will be a nonnegative integer • Hints I used two while loops- one to calculate the largest power of 2 less than or equal to the number, and - the other to print the bits one by one. My code only makes use of one other variable: unsigned int powerOfTwo; • to get started, you can try to reproduce the digits of the decimal number and then switch some 10s to 2s in your algorithm
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply