[Haskell-cafe] Endian conversion

Tomasz Zielonka tomasz.zielonka at gmail.com
Mon Oct 3 02:35:04 EDT 2005


On 10/3/05, Joel Reymont <joelr1 at gmail.com> wrote:
>
> Folks,
>
> Are there any endian conversion routines for Haskell? I'm looking to
> build binary packets on top of NewBinary.Binary but my data is coming
> in little-endian whereas I'll need to send it out big endian.


>From your question I assume you want functions like htonl / ntohl.
I think the cleanest approach is to always have yours Ints, etc in host
order, and place
the endianness stuff in serialization / deserialization code, ie. on the
Number <-> Byte
sequence boundary.

Having htonl/ntohl as pure functions in Haskell would be a bit ugly, because
they would be defined differently on different platforms, and putting them
in the
IO monad would make them barely usable.

Best regards
Tomasz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20051003/0431e703/attachment.htm


More information about the Haskell-Cafe mailing list