xxd examples of big/little/middle endianness (thanks @jilles_com!)
Posted by jpluimers on 2023/04/18
Cool one-liner program via [Archive] Jilles🏳️🌈 (@jilles_com) / Twitter:
for s in 0123456789ABCDEF 172.16.0.254 Passwd:admin;do echo -en "Big Endian: $s\nMiddle Endian: ";echo -n $s|xxd -e -g 4 | xxd -r;echo -en "\nLittle Endian: ";echo -n $s|xxd -e -g 2 | xxd -r;echo -en "\nReversed : ";echo -n $s|xxd -p -c1 | tac | xxd -p -r;echo -e "\n";done
Note that the hex are bytes, not nibbles, so the endianness is OK:
Big Endian: 0123456789ABCDEF Middle Endian: 32107654BA98FEDC Little Endian: 1032547698BADCFE Reversed : FEDCBA9876543210 Big Endian: 172.16.0.254 Middle Endian: .2710.61452. Little Endian: 71.2610.2.45 Reversed : 452.0.61.271 Big Endian: Passwd:admin Middle Endian: ssaPa:dwnimd Little Endian: aPssdwa:mdni Reversed : nimda:dwssaP
That nibble/byte thing confused me at first (as I associate hexadecimal output with hex dumps, where each hexadecimal character represents a nibble)) so here are some interesting messages from the thread that Jilles_com started:
- [Archive] Jilles🏳️🌈 on Twitter: “
for s in 0123456789ABCDEF 172.16.0.254 Passwd:admin;do echo -en "Big Endian: $s\nMiddle Endian: ";echo -n $s|xxd -e -g 4 | xxd -r;echo -en "\nLittle Endian: ";echo -n $s|xxd -e -g 2 | xxd -r;echo -en "\nReversed : ";echo -n $s|xxd -p -c1 | tac | xxd -p -r;echo -e "\n";done
…” / Twitter - [Archive] Jeroen Wiert Pluimers on Twitter: “@jilles_com Do both the byte and nibble order need to be reversed for little endian?” / Twitter
- [Archive] Jilles🏳️🌈 on Twitter: “@SchizoDuckie @jpluimers Big endian is normal, Little endian swaps 2 bytes, Middle endian swaps 4. And yes, middle endian is a thing. Especially on consumer routers ;-)” / Twitter
Some related man
pages:
- [Wayback/Archive]
tac
(1): concatenate/print files in reverse – Linux man page - [Wayback/Archive]
xxd
(1): make hexdump/do reverse – Linux man page - [Wayback/Archive]
echo
(1): line of text – Linux man page - [Wayback/Archive]
for
(1): perform set of commands multiple times – Linux man page - [Wayback/Archive]
man
(1): format/display on-line manual pages – Linux man page
–jeroen
Leave a Reply