是否有将二进制文件从小端转换为大端的oneliner?

Fer*_*ent 16 byte

反之亦然。

如果相关,我正在运行 RedHat。

sch*_*ily 36

您不能这样做,因为对于这样的转换,您需要知道二进制内容的含义。

例如,如果二进制文件中有一个字符串,则不得对其进行转换,并且 4 字节整数可能需要与两字节整数不同的处理。

换句话说,对于字节顺序转换,您需要一个数据类型描述。

  • 我就是想这么说。它并不像交换每对字节那么简单。例如一个 4 字节整数 01 02 03 04 在 bigendian 可能看起来像这样在 little endian 04 02 03 01 NOT 02 01 04 03 https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/字节序.html (7认同)

roa*_*ima 34

您可以使用dd. 够了吗?如果没有,请更新您的问题以提供输入文件和预期输出文件的示例。

echo hello >infile
dd conv=swab <infile >outfile

hex infile
   0000 68 65 6c 6c 6f 0a                                 hello.
hex outfile
   0000 65 68 6c 6c 0a 6f                                 ehll.o
Run Code Online (Sandbox Code Playgroud)


hes*_*_EE 6

为了更改文件字节顺序,假设字(32 位)大小,这 1 行应该适合您:

hexdump -v -e '1/4 "%08x"' -e '"\n"' input_file | xxd -r -p > output_file
Run Code Online (Sandbox Code Playgroud)