jeanluca:

Just to elaborate on the previous response a little bit: Some machines want the Most Significant Byte (MSB) of a word first in memory, while others want the Least Significant Byte (LSB) of a word to be first in memory. "Network Order" is a portable format that was (I think) specified in the TCP/IP RFCs so that machines of both endianness' could interoperate.

If you use network order in your binary formats, then you can make your code interoperable with other platforms. (Amusing note: Network order just happens to be the opposite byte order of the natural x86 order. So there's an incredible amount of time spent on x86 machines swapping byte orders to chat over networks. As there are more x86 machines out there than anything else, I wonder how many cycles are spent on it. But the people who worked on the original networking stuff apparently used boxes based on other CPU architectures than x86 (such as 3B2, 68000, 32032, etc.) so they got to choose!)

...roboticus


In reply to Re: swap binary data from big to little Endian by roboticus
in thread swap binary data from big to little Endian by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.