I'm trying to increase the limit up to a billion (or up to a hundred thousand). I don't know how.

``````main()
{
long int a,b,c,d=0,e=1;
clrscr();
printf(“Enter a Decimal Value: “);
scanf(“%ld”, &a);

while (a!=0)
{
b=a/2;                /*Formula for Decimal
c=a%2;                  to Binary*/
a=b;
d=d+(c*e);
e=e*10;
}

printf(“The Binary Value is: %ld”, d);

getch();
}
``````

## Recommended Answers

Even a four byte unsigned long int has a range of 0 to 4,294,967,295.

This is more than 4 billion and more than a hundred thousand. Unless you're using a PC from a very long time ago (decades ago), your long ints are at least this big.

So what is …

Well, I don't think going from a `long` to a `short` will help.

BTW, I suggest you look at where the comment is in relation to the modulo expression.

``````    b=a/2;                /*Formula for Decimal
c=a%2;                  to Binary*/
``````

As you have it here, the second …

## All 6 Replies

Even a four byte unsigned long int has a range of 0 to 4,294,967,295.

This is more than 4 billion and more than a hundred thousand. Unless you're using a PC from a very long time ago (decades ago), your long ints are at least this big.

So what is the actual problem? What does your code do that you think it shouldn't do, or what does it not do that you want it to do?

The problem is, when i type a value more than 1024, it produces a garbage value.

Also, which compiler are you using? If it is Turbo C, then you are limited to a `long` of 16 bits, which gives an `unsigned` maximum value of 65535.

so i'll do this instead?

``````unsigned short int a,b,c,d=0,e=1
``````

Well, I don't think going from a `long` to a `short` will help.

BTW, I suggest you look at where the comment is in relation to the modulo expression.

``````    b=a/2;                /*Formula for Decimal
c=a%2;                  to Binary*/
``````

As you have it here, the second line is getting commented out entirely.

why dont you implement this using a dynamic array so that you dont have that problem or atleast an integer array with a size of 100 or 1000 and try inputting it to the array at line 13 instead of adding it to d. you can consider the arrray as a stack or you may just output it from the last element upto the first one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.