/*Program for determining the decimal equivalent of a given 4-bit binary number*/ /*Author : Shekhar*/ main() { int a,b,c,d,e,f,g,h,x; clrscr(); x=100; while(x!=0) { clrscr(); printf("\n\t\tThis program will help you to find the decimal equivalent"); printf("\n\t\t of a given 4-bit binary number.\n"); printf("\n\t\tNote that the entered binary number should strictly be an"); printf("\n\t\t integer and should be exactly of Four Bits."); printf("\n\n\t\t Type 0 to Exit and 1 to continue the program :- "); scanf("%d",&x); switch(x) { case 0:clrscr(); printf("\n\n\n\n\n\n\n\t\t\t\tPROGRAM TERMINATED !"); printf("\n\n\n\t\t\tPress any key to return to object file..."); getch(); break; case 1:printf("\n\n\t\t Enter the Four-Bit Integer Binary Number:"); scanf("%d",&a); b=a%10; c=a/10; d=c%10; e=c/10; f=e%10; g=e/10; h=(b*1)+(d*2)+(f*4)+(g*8); if((b<0)||(b>1)||(d<0)||(d>1)||(f<0)||(f>1)||(g<0)||(g>1)) { clrscr(); printf("\n\n\n\n\n\n\n\n\t\t\t\t INVALID INPUT !"); printf("\n\n\n\n\t\t\t THE NUMBER IS EITHER NOT BINARY "); printf("\n\n\t\t\t OR EXEEDS FOUR BITS !"); getch(); break; } else { printf("\n\n\n\t\t\t\t\tA N S W E R"); printf("\n\n\t\t\tThe decimal equivalent of the number is %d.",h); printf("\n\n\t\t\t\tPress any key to continue..."); } getch(); break; default:clrscr(); printf("\n\n\n\n\n\n\n\t\t\t\tINVALID INPUT !"); printf("\n\n\n\t\t\t Press any key to continue..."); getch(); break; } } }