Hello :D I would like this to be explain.
What is meaning of this following codes and why are they in there? I really don't understand.
void Binary2Decimal()
total=0
"%16s"
len=strlen(bin2);
value=bin2[i]-'0';
total=(total<<1|value);
void Octal2Decimal()
for(i=0;i<len;++i)
value=buffer[i] - '0';
if (value < 0 && value > 7)
void Hexa2Decimal()
digit=toupper(buffer[i]);
if (digit >= '0' && digit <= '9')
value = digit - '0';
else if (digit >= 'A' && digit <= 'F')
value = digit - 'A' + 10;
else
printf("Invalid hexadecimal data\n");
return;
void Binary2Decimal()
{
char bin2[17];
int len,i,total=0,value;
gotoxy(1,13);printf("[BINARY TO DECIMAL CONVERSION]");
gotoxy(1,15);printf("Enter a Binary number: "); //Accept a maximum of 15 digits only in range of 32768.
scanf("%16s", bin2);
printf("\n");
len=strlen(bin2);
for(i=0;i<len;++i)
{
value=bin2[i]-'0';
if (value!=0 && value!=1)
{
printf("Invalid binary data\n");
return;
}
total=(total<<1|value);
}
printf("Decimal equivalent is: %d\n", total);
}
void Octal2Decimal()
{
char buffer[6];
int len,i,total=0,value;
gotoxy(1,13);printf("[OCTAL TO DECIMAL CONVERSION]");
gotoxy(1,15);printf("Enter an Octal number: "); //Accepts a maximum of 5 digits only in range of 32767.
scanf("%5s", buffer);
printf("\n");
len=strlen(buffer);
//Convert and check if we have a valid data
for(i=0;i<len;++i)
{
value=buffer[i] - '0';
if (value < 0 && value > 7)
{
printf("Invalid octal data\n");
return;
}
total = (total*8)+value;
}
printf("Decimal equivalent is: %d\n", total);
}
void Hexa2Decimal()
{
char buffer[5],digit;
int len,i,total=0,value;
gotoxy(1,13);printf("[HEXADECIMAL TO DECIMAL CONVERSION]");
gotoxy(1,15);printf("Enter a Hexadecimal number: "); //Accepts a maximum of 4 digits only in range of 32767.
scanf("%4s", buffer);
printf("\n");
len=strlen(buffer);
//Convert and check if we have valid data
for (i=0;i<len;++i)
{
digit=toupper(buffer[i]);
if (digit >= '0' && digit <= '9')
{
value = digit - '0';
}
else if (digit >= 'A' && digit <= 'F')
{
value = digit - 'A' + 10;
}
else
{
printf("Invalid hexadecimal data\n");
return;
}
total=(total*16)+value;
}
printf("Decimal equivalent is: %d\n", total);
}