Endian Converter Online – Byte Swap Calculator, Big/Little Endian, htonl/ntohl

Free online endian converter and byte swap calculator. Convert big endian to little endian with memory layout visualization, C bswap code generator, IEEE 754 float byte order, and htonl/ntohl reference for embedded and network developers

What is an Endian Converter?

An endian converter (also called a byte swap calculator) reverses the byte order of multi-byte values to convert between big endian and little endian representations. Every time a 16-bit, 32-bit, or 64-bit value crosses a byte-order boundary — from a network packet to a host CPU, from a Modbus register to an ARM Cortex-M, or from a binary file to a different platform — you need an endian conversion.

Most online endian converters only show you the swapped hex string. This tool goes further: it visualizes the byte-level memory layout at each address with color-coded cells so you can see exactly how bytes are rearranged. It also auto-generates C/C++ code snippets (using __builtin_bswap, manual bit-shifting, and union tricks) and displays the matching network byte order functions (htonl, ntohl, htons, ntohs, htobe64, be64toh) — everything you need to integrate the conversion into your firmware or application code.

This endian converter runs entirely in your browser via WebAssembly. No data is sent to any server. It supports 9 data types (uint8_t through double), 5 input formats (HEX, ASCII, Binary, Decimal, Octal), and handles multi-byte arrays by splitting input into type-sized chunks and converting each one independently.

How to Use This Endian Converter

  1. Choose Input Method — Select HEX for raw bytes (e.g. 0x12 0x34 0x56 0x78), ASCII for text strings, or Binary/Decimal/Octal.
  2. Select Data Type — Pick the C data type: uint16_t (2 bytes), uint32_t (4 bytes), float (IEEE 754, 4 bytes), uint64_t (8 bytes), double (IEEE 754, 8 bytes), or their signed variants.
  3. Set Source Byte Order — Choose whether your input bytes are in Big Endian (MSB first, network byte order) or Little Endian (LSB first, x86/ARM host order).
  4. Enter Data — Type your bytes. Multiple data type units are automatically split and converted separately (e.g. 8 bytes with uint32_t → two independent 4-byte conversions).
  5. Read Results — View source & converted values in Hex/Decimal/Binary simultaneously, the color-coded memory layout, the C code snippet, and the network function reference. Click any value to copy.

Big Endian vs Little Endian — Explained

Endianness (byte order) defines how a CPU stores multi-byte values in memory. The two conventions are named after the political factions in Jonathan Swift's Gulliver's Travels who argued over which end of an egg to crack.

Big Endian (BE) — Most Significant Byte First

Big endian stores the most significant byte (MSB) at the lowest memory address. This is the same order humans naturally read hex numbers. Network byte order is big endian (RFC 1700). Architectures that use or have used big endian include Motorola 68000, SPARC, IBM z/Architecture, and PowerPC (default).

uint32_t value 0x12345678 in Big Endian memory:

Address: 0x00 0x01 0x02 0x03

Value: [0x12] [0x34] [0x56] [0x78]

MSB LSB

Little Endian (LE) — Least Significant Byte First

Little endian stores the least significant byte (LSB) at the lowest memory address. It is the native byte order of Intel x86, AMD x86-64, ARM Cortex-M, ARM Cortex-A (default), and RISC-V — meaning the vast majority of modern CPUs. When you read a memory dump on these platforms, multi-byte values appear "reversed" compared to their logical hex value.

uint32_t value 0x12345678 in Little Endian memory:

Address: 0x00 0x01 0x02 0x03

Value: [0x78] [0x56] [0x34] [0x12]

LSB MSB

When Does Endianness Matter? — Practical Scenarios

Endianness bugs are notoriously hard to diagnose because the data looks almost right — just the bytes are in the wrong order. Here are the most common scenarios where you must perform endian conversion:

  • TCP/IP Network Programming: All IP, TCP, and UDP header fields are big endian. On little-endian hosts (x86, ARM), you must call htonl()/ntohl() for 32-bit fields and htons()/ntohs() for 16-bit fields (port numbers, sequence numbers, etc.). Forgetting this results in garbled IP addresses or wrong port numbers.
  • Modbus RTU / Modbus TCP: Modbus holding registers are 16-bit big endian. ARM Cortex-M (little endian) must byte-swap every register value. When 32-bit floats span two registers, you also face a word-order issue — some devices use AB CD order, others CD AB. This tool helps you visualize and verify both byte and word order.
  • CAN Bus / CAN FD: CAN signal byte ordering varies by DBC file definition. Intel (little endian) and Motorola (big endian) bit numbering within CAN frames are a common source of signal decoding errors.
  • Binary File Formats: BMP, WAV, and ELF (on x86) use little endian. TIFF, JPEG markers, Java .class files, and PDF cross-reference tables use big endian. Cross-platform parsers must check and convert byte order.
  • x86 / ARM Memory Dump Analysis: When inspecting hex dumps or debugger output on little-endian systems, a uint32_t with value 0xDEADBEEF appears as EF BE AD DE in the raw dump. This tool helps you reverse-map dump bytes back to logical values.
  • Firmware / Embedded Systems: STM32 (ARM Cortex-M, LE) communicating with a big-endian sensor over SPI/I2C must swap bytes. DSPs like TI C6000 can be big or little endian depending on boot configuration.
  • Cross-platform Serialization: Protocol Buffers uses varint (endian-neutral). MessagePack and CBOR use big endian for integers. Custom binary protocols must explicitly define byte order for every multi-byte field.

Endianness by Platform — Quick Reference

Platform / ArchitectureEndiannessNotes
Intel x86 / x86-64Little EndianAll modern PCs, servers, most laptops
ARM Cortex-M (STM32, nRF)Little EndianDefault; bi-endian in theory but LE in practice
ARM Cortex-A (Raspberry Pi)Little EndianLinux and Android run LE by default
Apple Silicon (M1/M2/M3)Little EndianARMv8.5-A, always LE
RISC-VLittle EndianSpec is LE; BE extension exists but rare
Network Protocols (TCP/IP)Big EndianRFC 1700 — "network byte order"
Modbus RTU / TCPBig Endian16-bit registers are BE; 32-bit word order varies
PowerPC / POWERBi-endian (default BE)POWER8+ supports LE mode for Linux
SPARCBig EndianClassic BE architecture (Oracle/Sun)
Java / JVMBig Endian.class files and DataOutputStream use BE

Endian Conversion in C/C++ — Code Examples

This tool auto-generates the C code for your specific value, but here is a quick reference of the standard approaches for byte swapping in C and C++.

Method 1: GCC / Clang Built-in Functions

The fastest approach — compiles to a single BSWAP instruction on x86:

  • uint16_t swapped = __builtin_bswap16(val);
  • uint32_t swapped = __builtin_bswap32(val);
  • uint64_t swapped = __builtin_bswap64(val);

On MSVC, use _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() from <stdlib.h>.

Method 2: Manual Bit-Shifting

Portable across all compilers:

uint32_t swapped = ((val & 0xFF000000) >> 24) | ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8) | ((val & 0x000000FF) << 24);

Method 3: POSIX Network Functions

  • #include <arpa/inet.h>
  • uint16_t net16 = htons(host16); // host → network (16-bit)
  • uint32_t net32 = htonl(host32); // host → network (32-bit)
  • uint16_t host16 = ntohs(net16); // network → host (16-bit)
  • uint32_t host32 = ntohl(net32); // network → host (32-bit)

For 64-bit: #include <endian.h>htobe64() / be64toh() (Linux/BSD).

Method 4: IEEE 754 Float / Double Swap

For floating-point types, swap via an integer intermediary:

  • uint32_t bits; memcpy(&bits, &float_val, 4);
  • bits = __builtin_bswap32(bits);
  • memcpy(&float_val, &bits, 4);

Never cast a float* to uint32_t* — this violates C strict aliasing and can cause undefined behavior. Always use memcpy() or a union (permitted in C99+, UB in C++ before C++20 std::bit_cast).

Modbus Endian Conversion — Register Byte Order

Modbus is one of the most common sources of endian confusion in industrial automation. Here is how byte ordering works in Modbus RTU and Modbus TCP:

16-bit Registers

Each Modbus holding register is 16 bits, transmitted MSB first (big endian). On a little-endian host (STM32, x86), you must swap bytes:

Example: Register value = 0x1234

Wire bytes (big endian): [0x12] [0x34]

After ntohs() on LE host: 0x1234 (correct)

Without swap on LE host: 0x3412 (wrong!)

32-bit Floats Across Two Registers

A 32-bit float occupies two consecutive 16-bit registers. The complication is that different devices use different word orders:

Float value 123.456 = 0x42F6E979 (IEEE 754)

  • Big Endian (AB CD): Register[0]=0x42F6, Register[1]=0xE979
  • Little Endian (CD AB): Register[0]=0xE979, Register[1]=0x42F6
  • Mid-Big (BA DC): Register[0]=0xF642, Register[1]=0x79E9
  • Mid-Little (DC BA): Register[0]=0x79E9, Register[1]=0xF642

If your Modbus device returns garbled float values, try changing the register/word order. This tool helps you verify which byte arrangement matches your expected value.

How This Online Endian Converter Works

This tool runs entirely in your browser using WebAssembly (Rust compiled to WASM). No data leaves your machine — all computation happens client-side.

Key Features

  • 9 data types: uint8_t, uint16_t, int16_t, uint32_t, int32_t, float (IEEE 754), uint64_t, int64_t, double (IEEE 754)
  • 5 input formats: HEX (0x / \x / raw), ASCII text, Binary (0b prefix), Decimal, Octal
  • Simultaneous output: Hex, Decimal, and Binary shown for both source and converted values at the same time
  • Memory layout visualization: Color-coded byte cells with addresses, MSB/LSB markers — see exactly how bytes move between big and little endian layouts
  • C code auto-generation: __builtin_bswap, manual shift, union trick — ready to paste into your project
  • Network function reference: htonl/ntohl for 32-bit, htons/ntohs for 16-bit, htobe64/be64toh for 64-bit
  • Multi-byte array mode: Enter multiple data units — they are split by type size and converted independently
  • Swap button: One click to feed the converted result back as input for round-trip verification
  • Persistent settings: Input mode, data type, and byte order are saved to browser localStorage

Frequently Asked Questions — Endian Converter

What is the difference between big endian and little endian?

Big endian stores the most significant byte (MSB) at the lowest memory address — the same order humans read hex numbers. Little endian stores the least significant byte (LSB) at the lowest address. For 0x12345678: big endian memory is [12 34 56 78], little endian memory is [78 56 34 12]. Network protocols (TCP/IP) use big endian; Intel x86, AMD64, and most ARM processors use little endian.

How do I convert big endian to little endian in C?

Use __builtin_bswap32(val) (GCC/Clang) or _byteswap_ulong(val) (MSVC) for 32-bit values. For portability, use ntohl(val) from <arpa/inet.h>. For manual conversion: ((val>>24)&0xFF) | ((val>>8)&0xFF00) | ((val<<8)&0xFF0000) | ((val<<24)&0xFF000000). This tool auto-generates the exact C code for your input value.

How do I byte-swap a float (IEEE 754)?

Copy the float to a uint32_t using memcpy(), swap the integer bytes, then copy back: uint32_t b; memcpy(&b, &f, 4); b = __builtin_bswap32(b); memcpy(&f, &b, 4); Never use pointer casts like *(uint32_t*)&f — it causes undefined behavior due to strict aliasing. In C99+, a union is also valid.

What is network byte order?

Network byte order is big endian, as standardized by RFC 1700 for all TCP/IP protocols. The BSD socket API provides conversion functions: htons()/ntohs() for 16-bit values (port numbers) and htonl()/ntohl() for 32-bit values (IP addresses). On big-endian hosts these are no-ops; on little-endian hosts they perform a byte swap.

Why does my Modbus device return wrong register values?

Modbus registers are 16-bit big endian. If your host is little endian (x86/ARM), you must byte-swap every register with ntohs(). For 32-bit floats split across two registers, the word order (which register comes first) varies by device manufacturer — try swapping register order if values seem garbled. See the Modbus section above for a detailed guide.

Is ARM big endian or little endian?

Almost all ARM systems run little endian. ARM Cortex-M (STM32, nRF52, LPC, etc.) and Cortex-A (Raspberry Pi, Android phones, Apple Silicon) default to little endian. While some ARM cores are technically bi-endian, in practice LE is universal. ARMv8/AArch64 is little endian by default.

What is the difference between byte order and bit order?

Byte order (endianness) affects the sequence of bytes within a multi-byte value in memory. Bit order affects the sequence of bits within a single byte during serial transmission (e.g. UART sends LSB first, SPI can be MSB or LSB first). Endian converters deal with byte order; bit order is handled by hardware peripherals.

How do I read a little-endian hex dump?

In a hex dump on x86/ARM (little endian), the bytes at consecutive addresses are in LSB-first order. To reconstruct a uint32_t from dump bytes 78 56 34 12, reverse them: the value is 0x12345678. This tool automates that: enter the dump bytes in HEX mode, select Little Endian as source, and read the converted Big Endian value.

Does endianness affect single bytes (uint8_t)?

No. Endianness only applies to multi-byte values. A single byte (uint8_t / char) is the same regardless of byte order. This tool shows a reminder message when uint8_t is selected.

What is middle-endian (mixed endian)?

Middle-endian (or mixed-endian) is a non-standard byte order where bytes are neither fully big nor little endian. The most famous example is the PDP-11, which stored 32-bit values as two 16-bit words in big-endian word order but little-endian byte order within each word. Some Modbus devices use a similar mixed order for 32-bit floats (BA DC or DC BA).

Related Tools

  • 3D Rotation Visualizer - Visualize 3D rotations using Quaternions, Euler Angles, and Rotation Matrices with interactive 3D visualization
  • Number Base Converter - Convert numbers between binary, decimal, hexadecimal, and octal with precision
  • Unit Converter - Convert between length, weight, temperature, pressure, speed, area, volume, data size, time, and energy units
  • 3D Rotation Converter - Convert between Quaternions, Euler Angles, and 3×3 Rotation Matrices bidirectionally with interactive 3D visualization

Input Settings

Conversion Settings

Input
HEX Mode
Supports: 0x01, \x02, x03, 04, 05 formats and combinations
Processed Data
Click to copy
Enter data above to see endian conversion results with memory layout visualization