Endian Converter

Source bytes (memory)

↓ byte order converted ↓

Result bytes (memory)

# Input hex Output hex Unsigned Signed Binary

Endian converter

This is an endian converter: it swaps the byte order of a multi-byte hex value in memory. Endianness is the byte order of a multi-byte value in memory. Identifiers such as big-endian, little-endian, PDP, uint32_t, htons, htonl, RFC 1700 and __builtin_bswap stay untranslated. For 0x12345678 big-endian memory is 12 34 56 78 (MSB first, network byte order). Little-endian (x86, ARM) is 78 56 34 12. PDP / middle-endian is 34 12 78 56. Show Example uses those four bytes, 32-bit, big-endian → little-endian. A 32-bit swap on two words AA BB CC DD 11 22 33 44 becomes DD CC BB AA 44 33 22 11; reverse-all on the same input is 44 33 22 11 DD CC BB AA.

How to use

  1. Paste hex. Spaces and 0x are ignored. Length must be a multiple of 2, 4 or 8 bytes unless you reverse all bytes.
  2. Pick 16-bit (uint16_t / htons), 32-bit (uint32_t / htonl) or 64-bit (htobe64). Each word is converted on its own.
  3. Set source and target to big-endian, little-endian or PDP. Swap ⇄ feeds the result back and flips the two orders.
  4. Read the color cells (index, hex, MSB/LSB), the table (unsigned, signed, binary) and the C snippet with __builtin_bswap.

Memory layout and values

The grid is the dump you would see in a debugger: address 0 is the left-most cell. Big-endian matches how humans write hex. Little-endian stores the least significant byte at the lowest address, so a dump of 0xDEADBEEF looks like EF BE AD DE. Unsigned is the integer after decoding with the source order; signed uses two’s complement of the same width. A single byte (uint8_t) has no endianness.

Network byte order, Modbus and C

TCP/IP fields are big-endian (RFC 1700). On a little-endian host you call htons/ntohs for 16-bit ports and htonl/ntohl for 32-bit values. GCC/Clang compile __builtin_bswap16/32/64 to a BSWAP instruction; MSVC uses _byteswap_ushort / _byteswap_ulong. Modbus registers are 16-bit big-endian; 32-bit floats across two registers may also need word order (AB CD vs CD AB). Swap IEEE 754 bits with memcpy into uint32_t, never *(uint32_t*)&f.

PDP / middle-endian

PDP-11 stored a 32-bit value as two 16-bit words in big-endian word order, with little-endian bytes inside each word. That is why 0x12345678 becomes 34 12 78 56. Some industrial devices still use mixed orders. 16-bit PDP is the same as swapping the two bytes (same as 16-bit little-endian if the source was big-endian).

Frequently asked questions

  • Why an error on 3 bytes with 32-bit? A 32-bit word needs a multiple of 4 bytes.
  • Is reverse-all the same as a 32-bit swap? Only for one word. Two words differ, as in the AA BB CC DD 11 22 33 44 example.
  • Floats? Use IEEE 754 for binary32/binary64, then this page to swap the hex bytes.
  • Does data leave the browser? No.

Related tools

Decode float bits with IEEE 754. Inspect a dump with Hex Dump. Read the integer with Hex to Decimal.

Working with integer values? Hex to Decimal →