Bitwise operators?

Aug 25, 2011 at 5:33 PM
Edited Aug 25, 2011 at 5:34 PM

Hi, thanks for your work on this library, it's really useful. 

Here are some stuff I found missing, but would be great to add IMHO:

- bitwise operators (&, |, &=, |=, etc...)

- random number generation (Random(IntX upperbound), and Random(IntX lowerbound, IntX upperbound))



Aug 26, 2011 at 4:43 PM

Thanks for the interest in my library.

I was thinking about adding bitwise operators but frankly not sure how are they supposed to work. For example, in IntX library negative numbers are represented not in two's complement form (when all bits set means "-1") so result of bitwise AND for two IntX numbers might be different from result of AND on two usual ints. This is kinda counterintuitive so I've decided to not implement bitwise operations at all - if you need them you can add an implementation which fits your needs :) Oh, and another problem with bitwise stuff is what to do about bitwise NOT for an arbitrary-precision integer - replace all the leading 0s with 1s will be kinda hard since there's practically infinite number of those.

As for random numbers generation - I don't think that IntX library itself is a good place for that. For me IntX is a primitive library, as small as it can be, and you can add random numbers generation by yourself by generating some random byte[] array and passing it to byte[]-consuming IntX constructor, using IntX.GetInternalState() to determine array size and "-", "%" operators to restrict resulting random number. Random byte[] array can be generated using System.Random class, for example.