Endianness Swap Calculator

Enter a hex value to swap its byte order.

How it is calculated

The tool removes a leading lower-case 0x and any spaces, then reads the rest as hexadecimal digits. If the digit count is odd, a 0 is added at the front so the value splits into whole bytes (0xABC becomes bytes 0A BC). The bytes are then written in reverse order: [b₀ b₁ … bₙ] → [bₙ … b₁ b₀]. Each byte stays intact, so only the order of byte pairs changes, never the order of the two digits inside a byte. The decimal figure is the value of the hex number as you entered it (after padding), not of the swapped one, and it is computed exactly for any length. Leading zero bytes count: 00001234 swaps to 0x34120000. Input containing anything other than 0-9 and a-f (such as # or the letter x elsewhere) gives no result.

Worked example

Enter 0x12345678. It splits into the four bytes 12, 34, 56 and 78. Reversing the byte order gives 78, 56, 34, 12, so the swapped value is 0x78563412. The decimal shown is for the original number: 0x12345678 equals 305419896. Reading the same four bytes as big-endian or little-endian therefore gives two different numbers, 305419896 or 2018915346.

Try this example →

Common mistakes

  • Reversing the hex digits instead of the bytes. Reversing 12345678 digit by digit would give 87654321, but the correct byte swap keeps each pair together and gives 78563412.
  • Reading the decimal result as the value of the swapped bytes. The decimal line belongs to the number you typed; to get the decimal of the swapped value, paste the swapped output back in.
  • Dropping leading zero bytes. 00001234 is a four-byte value, and its swap 34120000 keeps the zeros at the end; shortening the input to 1234 gives a two-byte swap, 3412.
  • Entering an odd number of digits and assuming the last digit is padded. The tool pads at the front, so ABC is treated as 0ABC, not ABC0.
  • Typing a capital 0X prefix. Only a lower-case 0x is stripped, so write 0x or leave the prefix off.

About this calculator

Endianness describes the byte order a system uses to store multi-byte values: big-endian stores the most significant byte first (this is “network byte order,” used in TCP/IP headers), while little-endian stores the least significant byte first (native to x86/x86-64 and most ARM configurations). Swapping means reversing the byte sequence — 0x12345678 becomes 0x78563412 — while the underlying decimal value only matches one interpretation or the other.

Network and embedded/firmware engineers hit this constantly when reading a packet capture, a binary file format, or register dumps from mixed-endian systems, since misreading the byte order silently produces a completely wrong number rather than an obvious error.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Pay attention to how many digits you type, because the swap works on whole bytes exactly as entered. If a field is four bytes wide, write 00001234, not 1234: the first swaps to 0x34120000, the second to 0x3412, which is a different answer. The decimal line always belongs to the number you typed, so convert the swapped hex separately if you need its decimal. Which protocol or file format are you working with?

Popular calculators

All Calculators