Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Write an application that inputs an integer of up to 8 digits containing only 0s and 1s (i.e., a "binary" integer) and print its decimal equivalent.  (Hint: Use the modulus and division operators to pick off the "binary" number's digits one at a time from right to left.  Just as in the decimal number system where the rightmost digit has a positional value of 1 and the next digit left has a positional value of 10, then 100, then 1000, etc., in the binary number system the rightmost digit has a positional value of 1, then the next digit left has a positional value of 2, then 4, then 8, etc.  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.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement