# Big-endian vs. little-endian in the context of bit-level encoding

**URL:** <https://forum.opencyphal.org/t/big-endian-vs-little-endian-in-the-context-of-bit-level-encoding/428>\
**Category:** Development & Maintenance\
**Created:** [April 6, 2019, 2:29am UTC](https://forum.opencyphal.org/t/big-endian-vs-little-endian-in-the-context-of-bit-level-encoding/428 "2019-04-06T02:29:23Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [February 23, 2020, 9:24pm UTC](https://forum.opencyphal.org/t/big-endian-vs-little-endian-in-the-context-of-bit-level-encoding/428/19 "2020-02-23T21:24:31Z")

</div>

One issue with the little-endian bit order is that it is poorly compatible with the implicit prefix alignment. By “implicit prefix alignment” I mean this: [Proposed change to variable-length arrays](https://forum.opencyphal.org/t/proposed-change-to-variable-length-arrays/740/6), note that it is applicable not only to arrays but to unions also.

Suppose we have a definition containing a variable-length array like this:

```
void5
uint8[<8] a

```

Or a definition containing a union of 8 fields:

```
void5
MyUnion.1.0 a

```

Denote the void bits `v`, the implicit prefix bits `i`, and the value bits `a`. The current, big-endian rule results in the following layout:

```
vvvvviii aaaaaaaa ...

```

Whereas the proposed little-endian rule results in the following layout:

```
iiivvvvv aaaaaaaa ...

```

Observe that only the former (i.e., current format) is equivalent to:

```
iiiiiiii aaaaaaaa ...

```

Only the current format allows implementations to substitute a pattern like `voidX + [u]intY` with `[u]int(X+Y)`.

This is not a major advantage, obviously, but the gains of the little-endian format are not high either.

As a reference, here is an implementation of the little-endian format in PyUAVCAN: [https://github.com/UAVCAN/pyuavcan/pull/99](https://github.com/UAVCAN/pyuavcan/pull/99)

---

_[View the full topic](https://forum.opencyphal.org/t/big-endian-vs-little-endian-in-the-context-of-bit-level-encoding/428)._
