# Byte ordering/conversion predicates?

**URL:** <https://swi-prolog.discourse.group/t/byte-ordering-conversion-predicates/4243>\
**Category:** Predicate\
**Created:** [August 3, 2021, 9:31pm UTC](https://swi-prolog.discourse.group/t/byte-ordering-conversion-predicates/4243 "2021-08-03T21:31:52Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [August 4, 2021, 7:51am UTC](https://swi-prolog.discourse.group/t/byte-ordering-conversion-predicates/4243/11 "2021-08-04T07:51:43Z")

</div>

> [@dmchurch](#):
>
> More generally, is there anything for doing binary-encoding of numeric data for interop with other systems?

AFAIK there is none as comprehensive as you seek.

However for [bit field](https://en.wikipedia.org/wiki/Bit_field) see;

> <https://github.com/SWI-Prolog/swipl-devel/blob/f366736edce5c642add2bd37b0c7be1f27f808b4/boot/syspred.pl#L116-L150>

To see them listed as code use:

```prolog
listing('$syspreds':map_bits/N).

```

Note: This is one of the rare cases where some of the clauses have two cuts in the same clause.

* * *

I don’t know if Jan W. would accept a PR adding more genialized such predicates in the boot level code but it does give one a general idea of what is needed to create a PR as a separate module.

* * *

Quite a while ago I did [post](https://swi-prolog.discourse.group/t/example-parse-of-binary-data-using-dcg/1370) some code that worked with streams of byte data and did some of these types of conversions.

[binary.pl](https://swi-prolog.discourse.group/uploads/short-url/2qMLZeeMcgB5VXFaVTdbNtzbHrY.pl) (9.9 KB)

---

_[View the full topic](https://swi-prolog.discourse.group/t/byte-ordering-conversion-predicates/4243)._
