Module bits

We provide a couple of additional bitwise operations. The evaluable functions bitcount/1, bitlength/1 and lowestsetbit/1 deal with the determination of certain bits of the given integer.

Examples:
bitlength(333)               --> 9

The evaluable functions setbit/2 and clearbit/2 update the given integer in a more efficient way than would be possible with existing logical and shift operations. The predicate testbit/2 tests a particular bit in a given integer, again the implementation is more efficient than would be possible with existing logical, shift and test operations.

The following bitwise evaluable functions are provided:

bitcount(X):
Predicate succeeds in N with the number of non-zero bits of X.
bitlength(X):
Predicate succeeds in N with the highest non-zero bit of X.
lowestsetbit(X):
Predicate succeeds in N with the lowest non-zero bit of X.
setbit(X, Y):
The predicate succeeds in Z with Y \/ (1 << X).
clearbit(X,Y):
The predicate succeeds in Z with Y /\ \ (1 << X).

The following built-in predicates are provided for bitwise extensions. The built-ins arithmetically evaluate their arguments before performing their tests:

testbit(X, Y):
The predicate succeeds when Y /\ (1 << X) =\= 0.

Comments