byte_order
Convert values between host and network byte order, handling little/big endian with optional fixed-width field grouping.
Instructions
Convert a value between host and network byte order (htons/htonl/ntohs/ntohl).
data is decoded via input_format (hex default). from_order/to_order
are little|big|network|host: network is big-endian, host resolves to the
platform's sys.byteorder — so on a little-endian box from_order=host
to_order=network is htonl/htons. width (bytes) sets a fixed field size: a
shorter buffer is left zero-padded up to width, a longer one is split into
width-byte groups each swapped independently (array semantics); omit it to
swap the whole buffer as one field. Differing orders reverse each field; equal
orders only apply the width normalization. Returns {result, from_order,
to_order, width, output_format}; result is rendered via output_format.
Example: byte_order("0x12345678", "little", "big") -> result "78563412"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Hex byte buffer (0x-prefix optional) to byte-swap, treated as a sequence of fixed-size `width`-byte fields. | |
| from_order | Yes | Current byte order of `data`: little|big|network|host (network=big-endian, host=platform's sys.byteorder). | |
| to_order | Yes | Target byte order: little|big|network|host. Differing orders reverse each field; equal orders only apply width normalization. | |
| width | No | Fixed field size in bytes: a shorter buffer is left zero-padded up to it, a longer one is split into width-byte groups each swapped independently. Default None swaps the whole buffer as one field. | |
| input_format | No | How `data` is decoded to bytes; default 'hex'. | hex |
| output_format | No | How `result` is rendered; default 'hex'. | hex |