# [Numpy-discussion] LittleEndian

Albert Strasheim fullung at gmail.com
Wed Jun 21 08:58:28 CDT 2006

```Hey Sheldon

With NumPy you can use dtype's newbyteorder method to convert any dtype's
byte order to an order you specify:

In [1]: import numpy as N
In [2]: x = N.array([1],dtype='<i4')
In [3]: y = N.array([1],dtype='>i4')
In [4]: xle = N.asarray(x, dtype=x.dtype.newbyteorder('<'))
In [5]: yle = N.asarray(y, dtype=y.dtype.newbyteorder('<'))

In [6]: x.dtype
Out[6]: dtype('<i4')

In [7]: y.dtype
Out[7]: dtype('>i4')

In [8]: xle.dtype
Out[8]: dtype('<i4')

In [9]: yle.dtype
Out[9]: dtype('<i4')

Regards,

Albert

> -----Original Message-----
> From: numpy-discussion-bounces at lists.sourceforge.net [mailto:numpy-
> discussion-bounces at lists.sourceforge.net] On Behalf Of Johnston Sheldon
> Sent: 21 June 2006 15:31
> To: Numpy-discussion at lists.sourceforge.net
> Subject: [Numpy-discussion] LittleEndian
>
> Hi,
>
> Can someone give a brief example of the Numeric function LittleEndian?
>
> I have written two separate functions to read binary data that can be
> either LittleEndian or BigEndian (using byteswapped() ) but it would be
> great with just one function.

```

More information about the Numpy-discussion mailing list