(Printing the Decimmal Equivalent of a Binary Number) Input an integer containing only 0s and 1s (i.e., a “binary” integer) and print its decimal equivalent. Use the modulus and division operators to pick off the “binary” number’s digits one at a time from right to left. Much as in the decimal number system, where the rightmost digit has a positional value of 1, the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 2 * 100 + 3 * 10 + 4 * 1. The decimal equiv- alent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8, or 13. [Note: To learn more abo
What will be an ideal response?
```
// Convert a binary value to its decimal equivalent.
#include
using namespace std;
int main()
{
int binary; // binary value
int bit = 1; // bit positional value
int decimal = 0; // decimal value
// prompt for and read in a binary number
cout << "Enter a binary number: ";
cin >> binary;
// convert to decimal equivalent
while ( binary != 0 )
{
decimal += binary % 10 * bit;
binary /= 10;
bit *= 2;
} // end while loop
cout << "Decimal is: " << decimal << endl;
} // end main
```
You might also like to view...
Which of the following topics is covered under the software development security CBK domain?
A. Understanding the cryptographic life cycle B. Understanding public key infrastructure C. Assessing the effectiveness of software security D. Securing network components
The SilentBanker man-in-the-browser attack depends on malicious code that is integrated into the browser. These browser helpers are essentially unlimited in what they can do. Suggest a design by which such helpers are more rigorously controlled. Does your approach limit the usefulness of such helpers?
What will be an ideal response?