Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- int bin{ 0 };
- int dec{ 0 };
- std::cin >> bin;
- for (int mul{ 1 }, bit{ 0 }; bin; mul *= 2, bin /= 10)
- {
- bit = bin % 10;
- if (bit != 0 and bit != 1)
- {
- std::cout << "Bad number!\n";
- return 1;
- }
- dec += bit * mul;
- }
- std::cout << "Decimal number: " << dec << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement