hex

xxd

    

Hexadecimal (hex) encoding and decoding are fundamental techniques for representing binary data in a human-readable format and converting it back to its original form. Hexadecimal is widely used in debugging, data analysis, and low-level programming due to its compact and readable representation of binary data.

In this form, you can encode text or files into hex or decode hex data back to its original form. The provided options offer flexibility for various encoding and decoding scenarios.


Key Features

Encode: Converts text or files into hexadecimal representation.
Decode: Converts hexadecimal data back to its original form.
File Input and Output: Enables specifying input files for encoding or decoding and output files for saving results.
Output Formatting: Customize line wrapping for hex output to enhance readability.


Common Hex Options

  • -p: Print plain hex encoding without addressing or line numbers.
  • -r: Reverse the process and decode hex back into the original data.
  • -c <width>: Specify the column width for wrapping the output lines (useful for structured hex output).
  • -i <file>: Specify the input file for encoding or decoding.
  • -o <file>: Specify the output file for saving results.
  • -a: Include ASCII representation alongside the hex output (useful for debugging).

Examples of Hex Commands

Encoding Examples

  • Encode text into hexadecimal:
    > echo "Hello, World!" | xxd -p
    Output: 48656c6c6f2c20576f726c6421
  • Encode a file named data.txt into hex:
    > xxd -p -i data.txt
  • Encode with 16-character line wrapping:
    > echo "This is a long string to encode." | xxd -c 16
    Output: 54686973 20697320 61206c6f 6e672073 7472696e 6720746f 20656e63 6f64652e

Decoding Examples

  • Decode a hex string back to text:
    > echo "48656c6c6f2c20576f726c6421" | xxd -r -p
    Output: Hello, World!
  • Decode a hex-encoded file encoded.hex:
    > xxd -r -i encoded.hex -o output.txt
  • Decode hex with ASCII representation:
    > echo "48656c6c6f" | xxd -r -p -a

Advanced Features

Line Wrapping: Specify a column width to structure output for easier readability, especially for long data streams.
Output File Options: Save encoded or decoded results directly to a specified file for further use.