[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing bytes to stdout reverses the bytes

On 2018-08-20, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> When I write bytes to stdout, why are they reversed?
> [steve at ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump
> 0000000 84fd 0804 000a
> 0000005

They aren't.  You're being fooled by the default output format of
hexdump.  By default, it displays data as 16-byte integers in
little-endian.  If you want to look at bytes, do this:

$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump -C
00000000  fd 84 04 08 0a                                    |.....|