|
Get 9,000+ Interview Questions with Answers in an eBook
C Source Codes List | Source Code Home
Program : Program to display the binary equivalent of a hexadecimal equivalent.
/* PRG TO DISPLAY THE BINARY EQUIVALENT OF AN I/P HEXADECIMAL NO. */
#include
#include
#include
void main()
{
char z[5],c;
int i=0;
clrscr();
printf("Enter a hexadecimal no.");
printf("\nNumber will be accepted if you press Ctrl-Z & then ENTER after inputting no.");
printf("\nNUMBER:- " );
while ((c=getchar())!=EOF)
{
printf(" ");
if (c=='1')
printf("0001");
else if (c=='2')
printf("0010");
else if (c=='3')
printf("0011");
else if (c=='4')
printf("0100");
else if (c=='5')
printf("0101");
else if (c=='6')
printf("0110");
else if (c=='7')
printf("0111");
else if (c=='8')
printf("1000");
else if (c=='9')
printf("1001");
else if (c=='A'||c=='a')
printf("1010");
else if (c=='B'||c=='b')
printf("1011");
else if (c=='C'||c=='c')
printf("1100");
else if (c=='D'||c=='d')
printf("1101");
else if (c=='E'||c=='e')
printf("1110");
else if (c=='F'||c=='f')
printf("1111");
else
{ printf("ERROR");
getch();
exit(0); }
}
printf("\n\t\t is its binary equivalent.");
getch();
}
C Source Codes List | Source Code Home
|
|
|