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.

Arguments:
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.

Arguments:
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.
 rbit(+Shift:integer, +Int:integer, ?Reverse:integer) is semidet
Bit reversal over a given span of bits. The reverse bits equal the mirror image of the original; integer $1$ reversed in 16 bits becomes $8000_{16}$ for instance.

Arity-3 rbit/3 predicate throws away the residual. Any bit values lying outside the shifting span disappear; they do not appear in the residual and the predicate discards them. The order of the sub-terms is not very important, except for failures. Placing succ first ensures that recursive shifting fails if Shift is not a positive integer; it triggers an exception if not actually an integer.

 xdigit_weights_and_bytes(?Weights:list(integer), ?Bytes:list(integer)) is semidet
Convert a list of hexadecimal digit weights to a list of bytes, or vice versa. Uses CLP(FD) constraints to ensure valid two-way conversions.

Examples:

?- xdigit_weights_and_bytes([10, 11, 12, 13], Bytes).
Bytes = [171, 205].

?- xdigit_weights_and_bytes(Weights, [171, 205]).
Weights = [10, 11, 12, 13].

This predicate is semidet, meaning it can succeed or fail depending on the input. The elements of the Weights list must be in the range 0..15, and the elements of the Bytes list must be in the range 0..255. The length of the Weights and Bytes lists must differ by a factor of two for the conversion to succeed. Two hexadecimal digit weights correspond to one byte.

Arguments:
Weights- A list of hexadecimal digit weights (0-15).
Bytes- A list of bytes (0-255).
 xbytes(?Bytes:list(integer))// is semidet
Converts a list of Bytes to a list of hexadecimal digits, or vice versa.

This predicate is semidet, meaning it can succeed or fail depending on the input. The elements of the Bytes list must be in the range 0..255.

Arguments:
Bytes- A list of bytes (0-255).

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)