BigInteger in c++

A

adrin

I have to create a c++ class similar to BigInteger from java...
but i have no idea, how can i implement big numbers at all(mabye store
every digit in list element? :))
how is it properly done?

thanks for help
 
I

Ioannis Vranos

adrin said:
I have to create a c++ class similar to BigInteger from java...
but i have no idea, how can i implement big numbers at all(mabye store
every digit in list element? :))


Perhaps you could use a vector of ints, longs or even bitsets.

how is it properly done?

Who knows?
 
G

Gianni Mariani

adrin said:
I have to create a c++ class similar to BigInteger from java...
but i have no idea, how can i implement big numbers at all(mabye store
every digit in list element? :))
how is it properly done?

Google for:

arbitrary precision c++ library

I have no first hand experience to talk about, however,

http://swox.com/gmp/

seems to be the best I can see.
 
G

gooch

"I have to create a c++ class similar to BigInteger from java...
but i have no idea, how can i implement big numbers at all(mabye store
every digit in list element? :))"

If by "each digit" you mean each bit representation I think that would
work. You just need to make sure you
can access individual bits so that the bit operations like shifting
etc. can be implemented without too much
problem. If by digit you mean 13 is represented by two nodes ( 1 and 3)
depending on how you store them
the bit manipulations could get confusing. I might create a register
class that can be
initialized to hold any arbitrary number of bits required by the user.
I would include operations such as
shift left, shift right, circular shift, and , or, etc. You could then
build your integer class using this register
class as a base.

"how is it properly done?"

I don't think there is a "proper" way. There are many good solutions to
most problems. Just think first about
the types of operations you will need to perform on this new type and
determine what information will
be needed to complete these operations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top