#include<iostream>
using namespace std;
void main()
{
int x;
cout<<"Enter any 4 bit binary number\n";
cin>>x;
int i1,i2,i3,i4,c1,c2;
i1=x/1000;
c1=x%1000;
i2=c1/100;
c2=c1%100;
i3=c2/10;
i4=c2%10;
if((i1==0 || i1==1)&&(i2==0 || i2==1)&&(i3==0 || i3==1)&&(i4==0 || i4==1))
{
int answer=(i1*8)+(i2*4)+(i3*2)+(i4*1);
cout<<x<<" in Decimal, Equals to: "<<answer<<endl;
}
else
cout<<"Error* Wrong input\nEnter Binary values (0 or 1)\n";
}
using namespace std;
void main()
{
int x;
cout<<"Enter any 4 bit binary number\n";
cin>>x;
int i1,i2,i3,i4,c1,c2;
i1=x/1000;
c1=x%1000;
i2=c1/100;
c2=c1%100;
i3=c2/10;
i4=c2%10;
if((i1==0 || i1==1)&&(i2==0 || i2==1)&&(i3==0 || i3==1)&&(i4==0 || i4==1))
{
int answer=(i1*8)+(i2*4)+(i3*2)+(i4*1);
cout<<x<<" in Decimal, Equals to: "<<answer<<endl;
}
else
cout<<"Error* Wrong input\nEnter Binary values (0 or 1)\n";
}
No comments:
Post a Comment