Adding to a bit array

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-04-26T23:09:51Z Indexed on 2010/04/26 23:13 UTC
Read the original article Hit count: 187

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about bitfoo

  • Easiest way to find the correct kademlia bucket

    as seen on Stack Overflow - Search for 'Stack Overflow'
    In the Kademlia protocol node IDs are 160 bit numbers. Nodes are stored in buckets, bucket 0 stores all the nodes which have the same ID as this node except for the very last bit, bucket 1 stores all the nodes which have the same ID as this node except for the last 2 bits, and so on for all 160 buckets… >>> More

  • Setting last N bits in an array

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I'm sure this is fairly simple, however I have a major mental block on it, so I need a little help here! I have an array of 5 integers, the array is already filled with some data. I want to set the last N bits of the array to be random noise. [int][int][int][int][int] set last 40 bits [unchanged][unchanged][unchanged][24… >>> More

  • Adding to a bit array

    as seen on Stack Overflow - Search for 'Stack Overflow'
    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… >>> More