mardi 4 août 2015

How to increase the potential value of an variable in a 16 bit machine using C

I have created a binary to decimal converter but even small numbers written in binary have many digits and thus are too large to be held by an integer variable on a 16 bit machine. Is there any way around this. The program is in C. Here is the code, thanks:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
 clrscr();
 int a,b,d=0,x=1;
 int check(int y);
 printf("Enter your number in Binary:");
 scanf("%d",&a);
 if(check(a)==0)
 {
  printf("Number tolerable. Conversion Process Initiated.");
 }
 else 
 {
  printf("Number not binary. Try again.");
  exit(1);
 }

 while(a!=0)
 {
   if(a%10==1)
    {
     d=d+x;
    }
   a=a/10;
   x=x*2;
 }
 printf("\nDecimal:%d",d);
 getch();
}

int check(int y)
{
  while(y!=0)
  {
   if(y%10!=0&&y%10!=1)
   {
    return 1;
   }
   else
   {
    y=y/10;
   }
  }
 return 0;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire