#include using namespace std; int main(void) { int binario; int decimale = 0; int potenza = 1; cout << "Inserisci un numero binario: "; cin >> binario; int temp = binario; while (temp > 0) { int cifra = temp % 10; if (cifra != 0 && cifra != 1) { cout << "Numero non valido!" << endl; return 0; } temp = temp / 10; } temp = binario; while (temp > 0) { decimale = decimale + (temp % 10) * potenza; temp = temp / 10; potenza = potenza * 2; } if (decimale < 0 || decimale > 255) { cout << "Numero non valido!" << endl; return 0; } cout << "Numero decimale: " << decimale << endl; return 0; }