Skip to main content
Byte Array Tools

Hex to Byte Array Converter

Convert a hex string such as DEADBEEF, de:ad:be:ef or 0xDE, 0xAD into a byte array, as a plain list or code for C, Java, Python, Go, Rust and more.

Paste hex in any common layout - with or without spaces, colons or 0x prefixes - and get the bytes as a list or an array declaration.

Spaces, colons, dashes, commas, 0x and \x prefixes are all fine: DEADBEEF, de:ad:be:ef, 0xDE, 0xAD.

Each byte is exactly two hex digits, so an odd number of digits usually means a character was lost when copying.

What Is the Hex to Byte Array Converter?

It turns a hexadecimal string into a byte array. Every two hex digits are one byte. The tool accepts the formats you meet in practice - DEADBEEF, de ad be ef, de:ad:be:ef (as in MAC addresses and certificate fingerprints), 0xDE, 0xAD and \xde\xad - and writes the bytes as a list or as an array for your language.

When to Use It

  • Turning a hash, key or UUID from hex into bytes for a test or a constant.
  • Converting hex copied from Wireshark or a hex editor into code.
  • Replacing the hand-written bytes.fromhex() or Hex.decode() call in a quick experiment.

How to Use It

  1. Paste the hex string - separators and prefixes are ignored.
  2. Choose the output language, number format, values per line and variable name.
  3. Copy the result.

Example

DE:AD:BE:EF:CA:FE:BA:BE as Python in hex gives data = bytes([0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE]) - eight bytes.

Understanding the Output

The byte count is half the number of hex digits. Choose decimal output if the receiving code expects numbers from 0 to 255, or tick "signed" to get -128 to 127 as Java uses.

Limitations

An odd number of digits is reported as an error rather than guessed, because a missing digit usually means something was lost when copying. The tool reads a hex string; to convert a single hex number to decimal use Hex to Decimal. For the reverse direction, use Byte Array to Hex.

Frequently Asked Questions

Continuous hex (DEADBEEF), hex separated by spaces, colons, dashes or commas (de:ad:be:ef), 0x-prefixed values (0xDE, 0xAD) and \x escapes (\xde\xad). Upper and lower case are both fine.

Each byte is exactly two hex digits, so a valid hex string always has an even number of digits. An odd count usually means a digit was lost or added when copying. Check the start and end of the string.

In Python use bytes.fromhex("deadbeef"). In Java 17+ use HexFormat.of().parseHex("deadbeef"). In JavaScript (Node.js) use Buffer.from("deadbeef", "hex"). In Go use hex.DecodeString("deadbeef").
Share this tool: