Hex to Decimal

Little endian hex to decimal converter

Paste bytes as they appear in memory or a file. The tool reverses them and gives the decimal value both ways. Below: what little endian means, the reversal method, a method that skips it, signed values, byte widths and code.

Byte order lowest byte first in memory

Memory
Reversed
Little endian
Little endian, signed
Big endian
Big endian, signed

What little endian means

Little endian stores the least significant byte of a number at the lowest memory address. Big endian stores the most significant byte first, which matches the way people write numbers.

The 32-bit value 0x12345678 shows the difference. The four bytes sit in these orders:

Byte orderByte 0Byte 1Byte 2Byte 3
Big endian12345678
Little endian78563412

Only the byte order changes. The two hex digits inside each byte stay in place, so 78 does not become 87.

How to convert little endian hex to decimal

  1. Split the hex into bytes of two digits each: E8 03 00 00.
  2. Reverse the order of the bytes: 00 00 03 E8.
  3. Convert the reversed hex to decimal: 0x000003E8 = 3 × 256 + 14 × 16 + 8 = 1,000.

A second example uses 78 56 34 12. Reversed, it reads 12 34 56 78, which is 305,419,896 in decimal. For the digit-by-digit method, see how to convert hex to decimal by hand.

Convert without reversing the bytes

Multiply each byte by 256 raised to its position, counting from 0 at the first byte. The first byte is the least significant, so no reversal is needed.

E8 03 00 00 = E8 × 256⁰ + 03 × 256¹ + 00 × 256² + 00 × 256³
            = 232 × 1 + 3 × 256 + 0 + 0
            = 232 + 768
            = 1,000

This method suits short fields, such as 2-byte lengths in a file header, where reversing by eye takes longer than the sum.

Signed little endian values

Reverse the bytes first, then read the result as two's complement at the full byte width. The sign bit is the top bit of the last byte in memory, not the first.

Bytes in memoryWidthUnsignedSigned
FF 7F16-bit32,76732,767
18 FC FF FF32-bit4,294,966,296−1,000
FF FF FF FF32-bit4,294,967,295−1

The bytes 18 FC FF FF reverse to FF FF FC 18, which is 4,294,966,296 unsigned and −1,000 signed, since 4,294,966,296 − 2³² = −1,000. The signed hex to decimal converter explains two's complement at every width.

Byte width changes the answer

The same bytes give different numbers when you read them at a different width, so include every byte of the field. Dropping zero bytes is the most common cause of a wrong result.

BytesLittle endianBig endian
01 001256
2A 00 00 0042704,643,072
34 124,66013,330

Bytes 2A 00 00 00 read as 42 only when you treat all 4 bytes as one 32-bit integer.

Where little endian and big endian appear

x86, x86-64 and most ARM systems store integers in little endian, and network protocols send them in big endian. Big endian is also called network byte order.

  • Little endian: memory dumps and hex editor views on x86 and ARM machines, BMP and WAV files, and the registers and packets of many USB devices.
  • Big endian: IP, TCP and UDP headers, PNG chunk lengths, and the protocol fields that packet analysers such as Wireshark display.

A packet capture shows port 80 as 00 50, so it needs no reversal. The same port stored in memory on an x86 machine appears as 50 00. For IP addresses in both orders, use the hex to IP address converter. For floating-point bytes, see the hex to float converter.

Little endian hex to decimal in code

Python

int.from_bytes(bytes.fromhex("E8030000"), "little")   # 1000
int.from_bytes(bytes.fromhex("18FCFFFF"), "little", signed=True)   # -1000

JavaScript

const b = new Uint8Array([0xE8, 0x03, 0x00, 0x00]);
new DataView(b.buffer).getUint32(0, true);   // 1000
new DataView(b.buffer).getUint32(0, false);  // 3892510720 (big endian)

The second argument of getUint32 is true for little endian. See hex to decimal in JavaScript for parseInt and BigInt.

C

#include <stdint.h>

uint8_t b[4] = {0xE8, 0x03, 0x00, 0x00};
uint32_t v = (uint32_t)b[0] | (uint32_t)b[1] << 8 | (uint32_t)b[2] << 16 | (uint32_t)b[3] << 24;   // 1000

The shift version gives 1,000 on any processor. Copying the bytes with memcpy into a uint32_t gives 1,000 only on a little endian machine. For Python struct formats such as <I, see hex to decimal in Python.

Frequently asked questions

How do you convert little endian hex to decimal?
Reverse the order of the bytes, then convert the result as normal hex. E8 03 00 00 becomes 00 00 03 E8, which is 1,000.
Do you reverse the hex digits or the bytes?
Reverse the bytes, which are pairs of two digits. E8 03 becomes 03 E8, not 30 8E, because the two digits inside a byte keep their order.
What is the difference between little endian and big endian?
Little endian stores the least significant byte first, and big endian stores the most significant byte first. The 32-bit value 0x12345678 is 78 56 34 12 in little endian and 12 34 56 78 in big endian.
Why do processors use little endian?
Little endian puts the least significant byte at the base address, so the same address works for a value at 8, 16, 32 and 64 bits. Intel x86 and most ARM systems use it, and the choice is a design convention with no effect on the value.
Where do the names little endian and big endian come from?
Danny Cohen took the terms from Gulliver's Travels in his 1980 paper on byte order. In the book, two groups fight over which end of an egg to crack.
How do you read a hex dump that mixes byte orders?
Check the file format specification for each field. Many formats mix both orders, so a length field may be big endian while the data after it is little endian.