1

I have a byte stream, or more specifically an RTP packet. How can I change it from big endian to little endian?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
memeKing
  • 113
  • 2
  • 10
  • You can take a look at [Byte Order, Size, and Alignment](https://docs.python.org/2/library/struct.html#byte-order-size-and-alignment). – Vasilis G. Jan 08 '18 at 20:20
  • [\[SO\]: Python struct.pack() behavior](https://stackoverflow.com/questions/37990060/python-struct-pack-behavior) might come in handy. Or you can access lower level (*C*) functions via [\[Python\]: *ctypes* — A foreign function library for Python](https://docs.python.org/3/library/ctypes.html). – CristiFati Jan 08 '18 at 20:20

1 Answers1

0

I found out a solution. Place my data into a byte array, and simply reverse it. In hexadecimal, reversing pairs will change it from big-> little, little-> big etc. Therefore reversing a byte array, where each index is two hex pairs, the same applies.

Example, 0000 1F40 (Big endian) -> 401F 0000 (Little Endian) If each each two hex numbers represent a byte, i.e 1F or 40 are equal to one byte therefore reversing a byte array is equivalent.

memeKing
  • 113
  • 2
  • 10