Dan Sommers wrote:
> You could try the struct module.  If your input comes in fixed sized
> chunks, just call struct.unpack and struct.pack once per chunk.

Thanks, but it was a bit awkward to use for big chunks.

I ended up writing my own byteswapper in Pyrex:


def swapbytes(data):
  "Swap every two bytes of a even-sized python string, in place"
  cdef int i
  cdef char t, *p
  p = data
  for i from 0 <= i < len(data) / 2:
    t = p[0]
    p[0] = p[1]
    p[1] = t
    p = p + 2


Toby
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to