Command-line to reverse byte order/change endianess

后端 未结 6 1235
逝去的感伤
逝去的感伤 2021-02-07 18:49

I\'m hacking around in some scripts trying to parse some data written by Javas DataOutputStream#writeLong(...). Since java always seems to write big endian, I have

6条回答
  •  既然无缘
    2021-02-07 19:23

    BASH:

    od -b -v -w8 | while read pfx b8 ; do [ "$b8" ] && echo -n 12345678 | tr 87654321 \\${b8// /\\} ; done
    

    To be a bit more robust depending on the output style of od, it may need to compress spaces ( insert "| sed 's/ */ /g'" after the w8).

提交回复
热议问题