# operations on a big integer class

## Recommended Posts

Enigma_    100
Hello, I am an amateur programmer. I was interested in this problem I found to create a big integer class that can hold really big numbers. I attempted to make this class. Currently, I can do conditional operations on the numbers and addition, subtraction and multiplication operations. I put in some thought about how to divide 2 big numbers, but so far I have not made any significant progress. So I was wondering if anyone could give me some advice as to how I can tackle this problem. Any help is greatly appreciated. Thanks a lot

##### Share on other sites
Rattrap    3385
I've done some work on this. Division is one of the hardest parts to tackle. A couple of suggestions I have is to look into math using two's compliment and bit shifts.

By implementing two's compliment math into your code, you can get subtraction pretty easily.

A bit shfit to the left effectively multiplies a number by 2 (x2 for each individual bit shift), shifting to the right by a single shift gives you the equivelent of dividing by two. This can also make multiplication faster if implemented correctly, because you can usually break it down to a series of shifts and adds.

If I remember correctly, I had to do a combination of subtraction and bit shifting to produce relatively fast division on large numbers. There was a lot of logic involved figuring out when and how much to shift and when to subtract. It was definately way more intensive that the other operations.