The Swift library includes the function bigEndian
that can be used on integer types (such as Int
, UInt
, UInt8
, UInt64
, Int64
, etc) to convert them from host order (which might presumably be anything, but realistically will be big or little endian) to network byte order (which is big endian). There're some good SO answers referring to this, and a particularly complete one is here.
However, I've not found a good resource that covers arranging a Float
(32 bit) or Double
(64 bit) type in to network byte order. Given that these types don't have a bigEndian
method, I'm wondering if there is some subtlety involved? (The linked question does discuss floating point types, but I'm not sure it is definitely covering all details that might be relevant).
Specifically, I want to handle the 64 bit Double
floating point type. I'd like a solution that will work on any platform where Swift is available.
Thank you.