Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable limit problem with large number conversions

Status
Not open for further replies.

CrimsonHorn

Programmer
Sep 19, 2002
3
US
The project i'm working on is simple and and I have run into what I can only assume is a simple road block. I am tring to convert binary numbers into decimal. I have the actuall structure worked out, the problem I am runing into is that the largest number i can convert is somewhere in the neighborhood of 1020 something (the number 1111111111 in binary). I am not satisfied with having this limitation in my program. My approach is simple, I take the number as inputed from the keyboard and am currently storing it into a usigned long int
and using the tried and true % / method to evaluate and add the appropriate Multipul of Two to my decimal output variable.

Any suggestions would be greatly appreciated
Stephen
 
Try _int64.
unsigned long is only 32 bits wide.
 
I tried to utilize the _int64 but when I tested it I found that it was overflowing at the same point which my usigned long was... I am using stdio.h with the printf/scanf commands
when printing your _int64 variable which is the proper method of recall?
"printf ("%d", variable);"
"printf ("%u", variable);" etc.
I must confess that I am only just getting my feet wet here, as I understand it the character following the "%" represents a type of convertion, I would guess that this is where my problem lies. I had assumed that the _int64 would use the "%d" for decimal. Can you point out my folly? It would be greatly apreciated :)

thank you again for your time.
-Stephen
 
OK, if it's only a problem of displaying, why don't you
just show your result as string?
 
If it is the % / deal, you should probably look into the funtion <code>fmod( )</code>... It's included in math.h and takes two paramater. It should work with larger numbers than the normal mod (%), doubles to be exact.
 
It occured to me the other day that what I really need is the ability to evaluate each number as it is being input by the user. so that the problem of trying to store binary numbers into variables is no longer a problem, is there a command that would allow me to do this? I was orriginaly hoping to use such a method and input each individual &quot;1&quot; or &quot;0&quot; into an array at sepperate addresses. But the problem I ran into was that to the best of my knowlege scanf does not provide the ability to store each character into seperate adresses on an array.
any suggestions?

Thank you all for you time.
-Stephen
 
This may or may not help...

The function you might be wanted is in
Code:
stdio.h
:
Code:
int getchar( void )

What that will do is return (each/the next) char from the standard input (AKA stdin).

eg.

Persay the user the user &quot;1100010&quot;

Code:
char c = getchar();

while( c != EOF ) {
   putchar( c );
   c = getchar();
}

This will output 1100010 by going through each character one by one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top