View Full Version : Convert decimal to little-endian hex with bash commands?

December 16th, 2008, 04:30 AM
Does anyone know of an easy way to convert a decimal value to a little-endian hex value? I found at least a few ways of converting decimal to hex (big-endian):

echo "10 i 16 o <decimal number> p" | dc
echo "ibase=10; obase=16; <decimal number>" | bc

So if I convert say "9698547", I get "93FCF3", but I would like it to be in little-endian format or "F3FC93". Is there possibly an easy way to do this without making a bash script to swap the bytes around manually? Or is there maybe a single awk/sed command that would swap the bytes around? Thanks in advance for any help.