#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,sum=0,m,j;
char array[9];
printf("please enter an 8-bit binary number\n");
gets(array);/*Read an 8-bit binary number from the keyboard*/
for(i=0;i<8;i++){/*Convert the binary to its decimal equivalent.*/
m=1;
if(array[i]=='1'){
for(j=1;j<=8-i-1;j++)
m*=2;
sum+=m;
}
}
printf("Your input 8-bit binary number is:");
for(int p=0;p<8;p++)
printf("%c",array[p]);
printf("\nThe binary value is %d in decimal\n",sum);
printf("The binary value is %X in hexadecimal",sum);/*Convert the binary to its hexadecimal equivalent.*/
return 0;
}