Did you know ... Search Documentation:
Pack canny_tudor -- prolog/dcg/endian.pl
PublicShow source
 endian(?BigOrLittle, ?Width, ?Value)// is semidet
Applies big or little-endian ordering grammar to an integer Value of any Width.

Divides the problem in two: firstly the 'endianness' span which unifies an input or output phrase with the bit width of a value, and secondly the shifted bitwise-OR phase that translates between coded eight-bit octets and un-encoded integers of unlimited bit width by accumulation.

Arguments:
BigOrLittle- is the atom big or little specifying the endianness of the coded Value.
Width- is the multiple-of-eight bit width of the endian-ordered octet phrase.
Value- is the un-encoded integer value of unlimited bit width.
 big_endian(?Width, ?Value)// is semidet
Implements the grammar for endian(big, Width, Value) super-grammar.

In (-, +) mode the accumulator recurses first and then the residual Value_ merges with the accumulated Value because the first octet code is the most-significant byte of the value for big-endian integer representations, rather than the least-significant. The 0 =< H, H =< 255 guard conditions ensure failure for non-octet code items in the list.

 little_endian(?Width, ?Value)// is semidet
Implements endian(little, Width, Value) grammar.

Little-endian accumulators perform the same logical unification as for big-endian only in reverse. The only difference between big and little: recurse first or recurse last. Apart from that subtle but essential difference, the inner computation behaves identically.