bswap_64 - Linux


bswap_64 is a command-line utility that performs byte-swapping operations on 64-bit integers, effectively reversing the order of bytes within a 64-bit word. It is commonly used in low-level programming and data conversion tasks, where the byte order of data needs to be adjusted between different architectures or applications.


bswap_64 [-h] [--version] [--input-file <file>] [--output-file <file>] <value>


  • -h, –help: Display usage information
  • –version: Display version information
  • –input-file: Read 64-bit integer from a file
  • –output-file: Write swapped integer to a file


Example 1: Swapping a 64-bit integer from the terminal

echo 0x1234567890abcdef | bswap_64

Example 2: Swapping integers from a file

bswap_64 --input-file input.txt --output-file output.txt

Example 3: Swapping integers in a shell script



swapped_value=$(echo $value | bswap_64)

echo "Original value:   $value"
echo "Swapped value:   $swapped_value"

Common Issues

  • Ensure that the input provided is a valid 64-bit integer in hexadecimal format (starting with "0x").
  • Verify that the specified input and output files exist and have appropriate permissions.


bswap_64 can be used with other Linux commands and tools to achieve more complex tasks. For example:

  • Use awk to filter and extract 64-bit integers from a text file and pipe them to bswap_64 for swapping:
awk '{print "0x"$1}' input.txt | bswap_64

Related Commands

  • hexdump: Displays data in hexadecimal format
  • od: Dumps files in various formats, including hex
  • xxd: Hexadecimal and ASCII data dumper