Questions tagged [bitfoo]
5 questions
31
votes
6 answers
Zig Zag Decoding
In the google protocol buffers encoding overview, they introduce something called "Zig Zag Encoding", this takes signed numbers, which have a small magnitude, and creates a series of unsigned numbers which have a small magnitude.
For example
Encoded…

Martin
- 12,469
- 13
- 64
- 128
3
votes
10 answers
Finding the length of the common prefix in two bytes
Given two bytes, how would I find the length of the common bits at the start of the two bytes.
For example:
9 == 00001001
6 == 00000110
Common prefix is 0000, length 4
I'm working in C#, so please stick to C# operations only.
Addendum: This…

Martin
- 12,469
- 13
- 64
- 128
3
votes
2 answers
Easiest way to find the correct kademlia bucket
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…

Martin
- 12,469
- 13
- 64
- 128
2
votes
4 answers
Setting last N bits in an array
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…

Martin
- 12,469
- 13
- 64
- 128
1
vote
4 answers
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…

Martin
- 12,469
- 13
- 64
- 128