Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

C++ code for 4-bit Binary to Decimal conversion

#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";
}

No comments: