Did you know ... Search Documentation:
Pack canny_tudor -- prolog/canny/bits.pl
PublicShow source
 bits(+Shift, +Width, ?Word, ?Bits, ?Rest) is semidet
 bits(+ShiftWidthPair, ?Word, ?Bits, ?Rest) is semidet
 bits(+ShiftWidthPair, ?Word, ?Bits) is semidet
Unifies Bits within a Word using Shift and Width. All arguments are integers treated as words of arbitrary bit-width.

The implementation uses relational integer arithmetic, i.e. CLP(FD). Hence allows for forward and backward transformations from Word to Bits and vice versa. Integer Word applies a Shift and bit Width mask to integer Bits. Bits is always a smaller integer. Decomposes the problem into shifting and masking. Treats these operations separately.

Width- of Bits from Word after Shift. Width of zero always fails.
 bit_fields(+Fields:list, +Shift:integer, +Int:integer) is semidet
 bit_fields(+Fields:list, +Shift:integer, +Int0:integer, -Int:integer) is semidet
Two versions of the predicate unify Value:Width bit fields with integers. The arity-3 version requires a bound Int from which to find unbound (or bound) values in the Fields; used to extract values from integers else check values semi-deterministically. The arity-4 version of the predicate accumulates bit-field values by OR-wise merging shifted bits from Int0 to Int.

The predicates are semi-deterministic. They can fail. Failure occurs when the bit-field Width integers do not sum to Shift.

Fields- is a list of value and width terms of the form Value:Width where Width is an integer; Value is either a variable or an integer.
Shift- is an integer number of total bits, e.g. 8 for eight-bit bytes, 16 for sixteen-bit words and so on.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 bits(Arg1, Arg2, Arg3, Arg4)
 bits(Arg1, Arg2, Arg3)
 bit_fields(Arg1, Arg2, Arg3, Arg4)