Did you know ... | Search Documentation: |
Pack canny_tudor -- prolog/canny/endian.pl |
The endian predicates unify big- and little-endian words, longs and long words with lists of octets by applying shifts and masks to correctly align integer values with their endian-specific octet positions. They utilise integer-relational finite domain CLP(FD) predicates in order to implement forward and reverse translation between octets and integers.
Use of CLP allows the DCG clauses to express the integer relations between octets and their integer interpretations implicitly. The constraints simultaneously define a byte in terms of an octet and vice versa.
Example as follows: four octets to one big-endian 32-bit word.
?- phrase(big_endian(32, A), [4, 3, 2, 1]), format('~16r~n', [A]). 4030201