Question: Printing the Decimal Equivalent of a Binary Number (C Program) Input an integer (5 digits or fewer) containing only 0s and 1s (i.e., a binary

Printing the Decimal Equivalent of a Binary Number (C Program)

Input an integer (5 digits or fewer) containing only 0s and 1s (i.e., a binary integer) and print its decimal equivalent.

Hint: Use the remainder and division operators to pick off the binary numbers digits one at a time from right to left. Just as in the decimal number system, in which the rightmost digit has a positional value of 1, and 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 4 * 1 + 3 * 10 + 2 * 100. The decimal equivalent of binary 1101 is 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 or 1 + 0 + 4 + 8 or 13.

_____________________________________________________________________________

Example Output:

Enter a binary number (at most 5 digits)

1010

1010 => 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!