be_to_le.sh 336 B

123456789101112131415161718192021
  1. #!/bin/bash
  2. #
  3. # Converts a big-endian hex string to a little-endian hex string.
  4. #
  5. # Examples:
  6. #
  7. # ./be_to_le.sh 0x12345678
  8. # 0x78563412
  9. #
  10. # ./be_to_le.sh 12345678
  11. # 0x78563412
  12. BE_VALUE=$1
  13. # If the input starts with 0x, strip it off.
  14. if [[ $BE_VALUE =~ ^0x.* ]];
  15. then
  16. BE_VALUE=${BE_VALUE:2}
  17. fi
  18. echo 0x`echo -n $BE_VALUE | tac -rs ..`