Is there a simple command to reverse an hexadecimal number?
For example, given the hexadecimal number:
030201
The output should be:
010203
Using the rev
command, I get the following:
102030
Update
$ bash --version | head -n1
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
$ xxd -version
xxd V1.10 27oct98 by Juergen Weigert
$ rev --version
rev from util-linux 2.20.1
Best Answer
You can convert it to binary, reverse the bytes, optionally remove trailing newlines
rev
<2.24, and convert it back:Using
This does not work if the string contains the NUL byte, because
rev
will truncate the output at that point.