Is there a utility like hexdump that will handle non-native endian-ness?
At least for 16-bit words one can pipe it through dd conv=swab
as in,
cat file.dat | dd conv=swab | od -t x2
Is there a utility like hexdump that will handle non-native endian-ness?
Yes, the utility is called Perl.
Well actually Data::HexDumper - though you could roll your own.
number_format A string specifying how to format the data. It can be any of the following, which you will notice have the same meanings as they do to perl's pack function: C - unsigned char S - unsigned 16-bit, native endianness v or S< - unsigned 16-bit, little-endian n or S> - unsigned 16-bit, big-endian L - unsigned 32-bit, native endianness V or L< - unsigned 32-bit, little-endian N or L> - unsigned 32-bit, big-endian Q - unsigned 64-bit, native endianness Q< - unsigned 64-bit, little-endian Q> - unsigned 64-bit, big-endian
As pixelbeat suggests, you could use objcopy:
$ objcopy -I binary -O binary --reverse-bytes=num inputfile.bin outputfile.bin
where num
is 2 for 16 bit words, 4 for 32 bit words and 8 for 64 bit words.
Unfortunately objcopy has no option to accept input from stdin
or write output to stdout
, so in order to use it as a pipe you would need to write a wrapper script that creates temporary files.
This answer is copied from https://stackoverflow.com/a/19288235/1979048 and from https://serverfault.com/a/329207/157443.