Integers as bit arrays
Fri, 11 Jul 2003 14:26:55 -0500 (CDT)
My apologies if this has already been hashed to death. I did a search of
the archives and didn't find anything relevent.
What is the general opinion on being able to treat integers as bit arrays?
I'm thinking of volunteering to write this code, but before I do I want to
make sure that it's not greeted with "We discussed this a while ago and
decided it was a bad idea!"
The basic functionality I was thinking of implementing was:
- get, set (to 1), clear (to 0), invert individual bits
- get, set, clear, invert ranges of bits
- bitwise operators- and, or, xor, negation
- shifts (already implemented), rotates.
Points in it's favor:
- stop people from reimplementing the wheel
- usefull for EC crypto, other things
- Many possibilities for hand tuned assembler to increase performance, but
generic C gives OK performance.
- Makes GMP integers act more like C integers
Points against it:
- "odd" behavior, or serious performance problems, on non-binary systems
(BCD mainframes, etc)
- violates the mathematic concept of a number
- shows to the program how signed numbers work (2's complement, etc).
- only applies mpz-s, not mpq-s or mpf-s
Feedback is welcomed.