Binary To Decimal

  • Uploaded by: Muhammad Rana Farhan
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Binary To Decimal as PDF for free.

More details

  • Words: 131
  • Pages: 2
Q. Program convert binary number values (0,1) to decimal numbers. //INCLUDING LIBRARIES #include #include #include <stdlib.h> //BEGINING OF PRODRAM void main() { clrscr();

// CLEARING THE SCREEN

// INITIALIZATION OF VARIABLES int d1,d2,d3,d4,d5,d6,no=1,sum; // GETTING 6 DIGIT BINARY NO FROM USER cout<<"\nEnter 6 digit Binary No: "; cin>>d1>>d2>>d3>>d4>>d5>>d6; // CONDITION TO CHECK BINARY NO if ((d1!=1&&d1!=0)||(d2!=1&&d2!=0)||(d3!=1&&d3!=0)||(d4!=1&&d4! =0)||(d5!=1&&d5!=0)||(d6!=1&&d6!=0)) { cout<<"\n\nThe Entered No is not Binary..."; getch(); exit(0); } //CONDITIONS FOR CALCULATION OF DECIMAL EQUIVALENT NO if (d6==1) sum=1; else if (d6==0) sum=0; no*=2; if (d5==1) sum=sum+no; no*=2; if (d4==1) sum=sum+no;

no*=2; if (d3==1) sum=sum+no; no*=2; if (d2==1) sum=sum+no; no*=2; if (d1==1) sum=sum+no; // OUTPUT OF PROGRAM cout<<"\n\nThe Decimal No is: "<<sum; //END OF PRGRAM getch(); }

Click the link below to see more examples URL: http://ravianeducation.blogspot.com E-Mail: [email protected] Farhan: 03008855006

Related Documents


More Documents from ""

Factorial
June 2020 13
Lecture 10
June 2020 19
Scientific Calculator
June 2020 8
Intermediate Part Ii
June 2020 9
Intermediate Part Ii
June 2020 6