Search code examples
c#algorithmmathbit-manipulationbitfoo

Adding to a bit array


In my program, I am using BitArrays to represent 160 bit numbers. I want to be able to add, subtract, increment and decrement these numbers, what is the algorithm for doing this?

At the moment I'm not interested in multiplication and division, but I might be in the future so bonus points for that.

I'm implementing in C#, but pseudocode is fine if you're not familiar with the language


Solution

  • Since you are using C#, you might want to take a look at BigInteger which was added to the recently released .NET 4.0.