���As I understand it, the OP's problem is that he wants to
count bits from the high end, and Integers don't *have*
a finite high end.
PL/I has bit strings.�� Common Lisp has bit strings.
Some Schemes have copied Lisp.�� Eiffel _had_ bit strings,
more or less, but dropped them.
for documentation.
My own Smalltalk also has a BitArray class with a
somewhat different interface.�� Although developed
independently, both are implemented as byte arrays
with an associated count.�� It's not terribly hard.
For selecting small numbers of bits out of long
bit strings, this is more efficient than shifting
and masking a large integer.
I rather wonder whether it might be possible to do
better by thinking in a somewhat less C-like style.
For example, Erlang handles unpacking network
packets and the like by letting you write bit-string
*patterns*, which the compiler can then generate
special-case code for.
Run-time generation of small amounts of code is
somewhat easier in Smalltalk.�� (Most Smalltalks.)
What would it be like if you had a BitArray class
where you could say
������ extractor := BitArray extractorForBits: 3 to: 7 of: 256.
������ ...
������ extractor value: thisPacket
and extractor was a block (possibly cached) with
code specialised for just that case?