Byte ordering/conversion predicates?

For signed/unsigned integer conversion, at least int → uint is easily done with bitwise operators (UInt16 is Int16 /\ 0xffff). The other direction is a bit more annoying (UInt16 >= 0x8000 -> Int16 is UInt16 - 0x10000 ; Int16 = UInt16, or all in one expression: Int16 is UInt16 \/ (\0xffff * ((UInt16 >> 15) /\ 1))). A proper library or builtins for this would be more convenient of course.

Regarding converting integers from/to packed binary data, there was some related discussion a few months ago:

In that thread, @peter.ludemann also suggested the internal protobuf predicates mentioned above:

FWIW, I would also be interested in having binary un-/packing operations supported in SWI, and ideally not just as undocumented internal predicates that you have to call with a module prefix :slight_smile: I haven’t done much binary data parsing/generating with SWI yet, but it’s something I want to properly try out at some point.