FAQ
Hi, I was wondering how to get my data to be represented in little
endian format. I know that I can use the socket functions to convert to
network byte order (big endian), but I need to convert to little endian
(not just the host byte order).

Vic


Sent via Deja.com http://www.deja.com/
Before you buy.

Search Discussions

  • Andrew MacIntyre at Dec 7, 1999 at 8:26 pm

    On Tue, 7 Dec 1999 victor_ng at my-deja.com wrote:

    Hi, I was wondering how to get my data to be represented in little
    endian format. I know that I can use the socket functions to convert to
    network byte order (big endian), but I need to convert to little endian
    (not just the host byte order).
    module struct?

    --
    Andrew I MacIntyre "These thoughts are mine alone..."
    E-mail: andrew.macintyre at aba.gov.au (work) | Snail: PO Box 370
    andymac at bullseye.apana.org.au (play) | Belconnen ACT 2616
    Fido: Andrew MacIntyre, 3:620/243.18 | Australia
  • Fredrik Lundh at Dec 8, 1999 at 8:00 am

    Travis Oliphant wrote:
    Hi, I was wondering how to get my data to be represented in little
    endian format. I know that I can use the socket functions to convert to
    network byte order (big endian), but I need to convert to little endian
    (not just the host byte order).
    One possibility is to use the NumPy extensions and store your data in a
    multiarray object. There is a byteswapped method of the multiarray object
    that lets you byteswap your data.
    footnote: the standard array module also provides
    a byteswap operation:
    import array
    a = array.array("i", [1, 2])
    a
    array('i', [1, 2])
    a.byteswap()
    a
    array('i', [16777216, 33554432])
    There is also a way to check the endianness of your machine (so
    you can determine whether or not to byteswap).
    from array-example-4.py in the eff-bot guide:

    def little_endian():
    return ord(array.array("i",[1]).tostring()[0])

    </F>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 7, '99 at 6:24p
activeDec 8, '99 at 8:00a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase