Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- /**
- * Program reads zeros and ones from stdin and after terminating char 2 print decimal value of binary number.
- *
- * @return Returns 1 if wrong input is detected, 0 if everything ok.
- * @author Michael Hartman [email protected]
- */
- int main ( int argc, char ** argv )
- {
- short i;
- unsigned int num = 0;
- while ( 1 )
- {
- if ( ! ( std::cin >> i ) || ( i != 0 && i != 1 && i != 2 ) )
- {
- std::cerr << "Wrong input!" << std::endl;
- return 1;
- }
- if ( i == 2 )
- break;
- num <<= 1;
- num |= (unsigned int) i;
- }
- std::cout << "vysledna hodnota je " << num << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment