Write a program that reads in an unsigned integer containing only 0s and 1s (i.e. a "binary" integer) and outputs its decimal equivalent. Use the modulus and division operators to pick off the "binary" number's digits one at a time from rigiht to left. Much as in the decimal number system, where the rightmost digit has a positional value of 1 (=100), the next digit left has a positional value of 10 (=101), then 100 (=102), then 1000 (=103), and so on, in the binary number system the rightmost digit has a positional value of 1 (=20), the next digit left has a positional value of 2 (=21), then 4 (=22), then 8 (=23), and so on. Thus, the decimal number 234 can be interpreted as 2*100 + 3*10 + 4*1.
Your program must accept only (unsigned) "binary"integers containing only 0s and 1s. Do not read in the integer as a string object. Use a loop to validate the input: the user should get stuck entering a "binary" integer if the value entered is not of the right form.
I don't understand how to start the program off using the modulus and division operators to seperate the number into digits. Does anybody have any suggestions? I just started programming and this is my first assignment.