Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main()
- {
- string text="";
- int input=0;
- cout << "Zadej cislo ve dvojkove soustave:" << endl;
- getline(cin, text);
- for(int i = 0; i < text.size(); i++)
- {
- char ch = text[i];
- if((ch != '0') && (ch != '1'))
- {
- cout << "Nespravny vstup." << endl;
- return(0);
- }
- }
- istringstream(text) >> input;
- unsigned long long output = 0;
- unsigned long long weight = (1ull << (text.size() - 1));
- for(int i = 0; i < text.size(); i++) {
- output += (text[i] - '0') * weight;
- weight = weight >> 1;
- }
- cout << text << endl;
- cout << "Desitkove cislo je: " << output << endl;
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment