• Advertisement

Archived

This topic is now archived and is closed to further replies.

Little endian to host?

This topic is 5093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if the sockets libraries (or any others) had a function to convert little endian to host that I overlooked (like ntohl)? Or should I roll my own? [edited by - Puzzler183 on February 8, 2004 9:11:07 PM]

Share this post


Link to post
Share on other sites
Advertisement
you mean little endian to big endian byte ordering aka network order? O_o

Share this post


Link to post
Share on other sites
Something like that only not. Little endian -> local machine order is what I''m looking for, but apparently it doesn''t exist (big endian -> local does, ntohl and its peers).

Share this post


Link to post
Share on other sites
OK, as if I''m not making myself clear, I understand what htonl and ntohl do. I''m not a moron. Thye don''t do what I need though. They do local machine <==> network (big endian). I want local machine <==> little endian. Anyway, screw it, I''ll just roll my own.

Share this post


Link to post
Share on other sites
Why does endianness matter, anyway? Can''t you just say "I''ll store things in network byte order and reverse it to host order on load?"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Probably for file format releated things (load and save from host to little endian file format).

To answer the specific question, you''ll have to roll your own. I don''t think any of the standard libraries have this functionality.

Share this post


Link to post
Share on other sites
No standard functions can do it. So you gotta write your own.

I wonder why though. Since the network (Big Endian) functions
are readily available, I expect most people would save binary
formats in Big Endian formats. I do.



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Pretty much any "standard" file format that originated on x86 is little endian. .3ds is a good example. All multi-byte values are stored in little endian form.

Share this post


Link to post
Share on other sites
I''m specifically concerned with Targa''s and BMP''s although I expect problems later with file formats as well.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Pretty much any "standard" file format that originated on x86 is little endian. .3ds is a good example. All multi-byte values are stored in little endian form.




That can mean one of two (maybe more) things:

- The format was not designed with endianness, thus portability,
in mind. (Who cares? I just use it on Wintel machines!)

- The format is supposed to be portable, but the programmers
decided it was fun to write their own Little-Endian conversion
functions.

OK, it may also be that the format designer was not aware
of such a thing as "endianness".



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
Or it may just mean that they evaluated the pros and cons of the alternatives and (rightly) decided that little-endian was the way to go, as its downside (harder to read memory dumps and so on) is negligible compared to its upside (simpler for hardware, reduced need for pointer fixups).

Share this post


Link to post
Share on other sites

  • Advertisement