TestBench.tools
GitHub

Endianness Converter

Swap byte order of hex values: 16/32/64-bit, word swap.

4 bytes (32-bit)

Byte-reversed (full endianness flip)
78 56 34 12
Byte swap within 16-bit words (AB CD → BA DC)
34 12 78 56
16-bit word swap within 32-bit (AB CD EF GH → EF GH AB CD)
56 78 12 34
Original
12 34 56 78

This tool reorders the bytes of a hex value every way that occurs in practice: full byte reversal (big ↔ little endian), byte swap inside each 16-bit word, and 16-bit word swap inside each 32-bit group. Paste the bytes you captured and compare the three outputs against what you expected — the matching transform tells you exactly how the producing system stores data.

How it works

A multi-byte value has no inherent byte order — 0x12345678 can sit in memory as 12 34 56 78 (big-endian, network order) or 78 56 34 12 (little-endian, x86 and most MCUs). Protocols and file formats each pick a convention, and every boundary between conventions is a chance for corruption. The three transforms here cover the real-world cases: full reversal for endianness conversion, adjacent-byte swap for 16-bit-oriented transports, and 16-bit word swap for the register-pair orderings PLC vendors use.

Worked example

input             : 12 34 56 78
byte-reversed   : 78 56 34 12  (big ↔ little)
16-bit byte swap: 34 12 78 56
word swap       : 56 78 12 34  (ABCD → CDAB)

Parameters

ParameterValueNotes
Byte reversalany lengthfull endianness flip
16-bit byte swapeven byte countsAB CD → BA DC
Word swapmultiples of 4 bytesAB CD EF GH → EF GH AB CD
Input formathex bytesspaces / 0x prefixes accepted

C implementation

C
#include <stdint.h>

uint16_t swap16(uint16_t v) { return (v >> 8) | (v << 8); }

uint32_t swap32(uint32_t v)
{
    return ((v & 0x000000FFu) << 24) | ((v & 0x0000FF00u) << 8) |
           ((v & 0x00FF0000u) >> 8)  | ((v & 0xFF000000u) >> 24);
}

/* 32-bit word swap (ABCD -> CDAB), the classic Modbus fix: */
uint32_t wordswap32(uint32_t v) { return (v >> 16) | (v << 16); }

FAQ

▸What is endianness in one sentence?

It is the order in which a multi-byte value's bytes are stored or transmitted: big-endian puts the most significant byte first (0x12345678 → 12 34 56 78), little-endian puts the least significant byte first (78 56 34 12).

▸Which swap do I need — byte reversal, byte swap, or word swap?

Full byte reversal converts between big- and little-endian of the whole value. 'Byte swap within 16-bit words' fixes data that passed through a system treating memory as 16-bit units (common with Modbus registers). 'Word swap' reorders the two 16-bit halves of a 32-bit value — the CDAB arrangement many PLCs use. This tool shows all three so you can pattern-match against what your device produces.

▸Why do Modbus 32-bit values often need a word swap rather than a byte swap?

Modbus transfers data as 16-bit registers, and each register travels big-endian. Vendors disagree only about the order of the two registers, so mismatches show up as swapped 16-bit halves (CDAB) rather than fully reversed bytes.

▸How can I tell my capture is byte-swapped?

Numbers look wildly wrong but not random — e.g. an expected small integer decodes as a huge one, and ASCII text appears with characters pairwise exchanged ('eHll o'). Run the bytes through the three transforms here and see which one produces sensible values.

▸Is my data uploaded?

No. All transforms run locally in your browser.

Related tools