ForHosting KIT · Developer Utilities

Byte-order swap calculator

0x12345678 becomes 0x78563412 when its four bytes are reversed, the step between network order and little-endian memory. Pick a width of 8, 16, 32 or 64 bits and see the value before and after in hex, decimal and byte by byte. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Value
0x12345678
Width
32
You get
Byte count
4
Hex before
0x12345678
Hex after
0x78563412
Decimal before
305419896

Network stacks, file formats, and embedded firmware constantly disagree about whether the most significant byte of an integer comes first or last. A length field that looks like 0x12345678 on the wire is stored as 0x78563412 in little-endian memory, and the reverse trip is just as common when you dump a register and need the network-order value. This byte-order swap calculator accepts an integer and a bit width of 8, 16, 32, or 64, reverses the bytes inside that container, and returns the hexadecimal value before and after the swap together with the matching decimal forms and byte arrays.

What a byte-order swap does at 8, 16, 32, and 64 bits

An unsigned multi-byte integer is a sequence of bytes whose significance depends on endianness. Written in the usual place-value way, 0x12345678 means the most significant byte is 0x12 and the least significant byte is 0x78. Big-endian storage lays those bytes down in that same order; little-endian storage reverses them so memory holds 78 56 34 12.

Swapping byte order is exactly that reversal inside a fixed-width container: the 32-bit swap of 0x12345678 is 0x78563412, the 16-bit swap of 0x1234 is 0x3412, and an 8-bit value is unchanged because a single byte has no order to flip. A 64-bit swap does the same walk across eight bytes, which is why 0x0123456789ABCDEF becomes 0xEFCDAB8967452301. Hardware names this instruction bswap; POSIX network helpers such as htons, htonl, ntohs, and ntohl are the same reversal when host order is little-endian.

This calculator does not guess your platform and does not need a from-endian flag: you supply the integer as humans write it (or as a 0x hex string) and a width, and the result is the integer whose bytes are the reverse of that width. Applying the swap twice restores the original value, which makes it a safe round-trip for tests that convert host integers to network order and back.

When swapping byte order helps

Protocol reverse engineering, packet crafts, and CTF binary challenges constantly need a trusted bswap so a hex dump from Wireshark and a little-endian register dump can be compared without flipping bytes by hand. Embedded and firmware teams convert configuration constants, CRC seeds, and magic numbers between network order and the MCU's host order when writing headers or checking flash images.

Teachers explaining endianness need a live oracle that holds the integer fixed and only reverses bytes at a chosen width, so students see why htons on 0x1234 is 0x3412 on a little-endian host. Continuous-integration scripts that mint test vectors for serializers benefit from a tiny pure function instead of pulling a full binary toolkit for one integer. Failed validation does not consume balance.

Keep requests small, pin the hex strings in tests, and you get a reproducible endian swap for homework, parsers, and edge workers.

Network order and host order

Convert a 16-bit or 32-bit integer between big-endian wire format and little-endian host memory the same way htons, htonl, ntohs, and ntohl do.

Firmware constants and hex dumps

Reverse the bytes of magic numbers, lengths, and CRC seeds when a hex dump and a C integer literal disagree about endianness.

Teaching endianness

Show both hexadecimal forms of the same integer at 8, 16, 32, or 64 bits so students see that a swap is just reversing the bytes.

How do I swap the byte order of an integer?

Send value (decimal or 0x hex) and width (8, 16, 32, or 64).

Is this the same as htons or bswap?

Yes. At 16 bits it matches htons/ntohs on a little-endian host; at 32 bits it matches htonl/ntohl and a 32-bit bswap; at 64 bits it matches an 8-byte bswap.

What happens if the value does not fit the width?

The calculator does not wrap or truncate; choose a wider container or pass a value that fits.

Are negative numbers allowed?

Yes. A negative value is converted to two's complement at the chosen width, then the bytes of that unsigned pattern are reversed.

Do I need to say whether my value is big-endian or little-endian?

No. Enter the integer the way you would write it, in decimal or as hex with 0x, and pick the width. The result is the integer whose bytes are reversed within that width, with no guess about your machine.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/byte-order-swap

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/byte-order-swap \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value":"0x12345678","width":32}'
{
  "value": "0x12345678",
  "width": 32
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.byte_order_swap",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Values that do not fit the chosen width, missing fields, and illegal widths fail with invalid_input instead of silently wrapping.

Input contract, response shape, and error behaviour

Optional number fields are omitted rather than set to null when a 64-bit result would not be exact. POST a JSON body with two required fields: value, the integer to swap, and width, the bit width of the container. Value may be a JSON number, a decimal string, a 0x-prefixed hexadecimal string, or an optional 0b binary string; aliases number, n, integer, and hex are accepted. Width must be 8, 16, 32, or 64 (aliases bits, bit_width, and size) and may arrive as a number or as a short token such as 32bit. The integer must fit the chosen width: non-negative values may be at most two to the width minus one, and negative values are interpreted as two's complement and must sit in the signed range for that width. Overflow, a missing field, an empty string, a non-integer, or a width outside the closed set fails with invalid_input naming the field; those failures are not billed. On success the body includes width and byte_count; hex_before and hex_after as zero-padded uppercase 0x strings; decimal_before and decimal_after as exact decimal strings so 64-bit results never lose digits; bytes_before and bytes_after as MSB-first arrays of 0–255; and, when each magnitude fits JavaScript's safe integer range, decimal_before_number and decimal_after_number. Example: value 0x12345678 and width 32 yields hex_before 0x12345678, hex_after 0x78563412, and bytes 18,52,86,120 reversed to 120,86,52,18.

Where a byte-order swap API earns its keep

Content sites that rank for byte order swap calculator gain a free browser path that matches the paid API byte-for-byte on the same module.

What does the byte-order swap calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →