Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #2494

Re: little-endian

From BGB <cr88192@hotmail.com>
Newsgroups comp.programming
Subject Re: little-endian
Date 2012-11-17 11:30 -0600
Organization albasani.net
Message-ID <k88hoj$fvl$1@news.albasani.net> (permalink)
References (1 earlier) <jnpaa811us6aub4qqsevj60iatfs95tbrj@4ax.com> <f9e47587-00b6-4292-b12c-bc5b62b9d54c@googlegroups.com> <87r4ntp4b1.fsf@informatimago.com> <k86vq4$hl0$1@news.albasani.net> <87mwygpolg.fsf@informatimago.com>

Show all headers | View raw


On 11/17/2012 3:26 AM, Pascal J. Bourguignon wrote:
> BGB <cr88192@hotmail.com> writes:
>
>> some of my file-formats end up little-endian, and others big-endian.
>
> That's unfortunate.  The internet is in general specified to use
> big-endian.  For files you'd be well advised to apply the same rule.
>
> Always use htonl to write to files/network and ntohl to read from
> files/network.
>

granted though, many file formats (in general) are designed in a world 
where the dominant processor architectures (namely x86 and ARM) use 
little-endian.

a lot often comes down to whether the original designer felt like big or 
little endian, or if the format it is based on uses big or little, where 
mostly it is just good to be consistent (as formats which are partly in 
big and partly in little are a little ugly...).



typically, a person may develop and use functions like:
ReadInt32BE
and WriteInt64LE and similar, and use these for most of the encoding.


also, a big downside of using htonl and ntohl as a general mechanism is 
that it makes all of ones' libraries need to depend on winsock.

also, "word flipping" is sort of an ugly trick IMO, better to just 
read/write values with an explicit endianess.



>
>> then (when dealing with bitstream formats) there is also the whole
>> matter of bit-ordering, which may or may not match the byte-ordering.
>
> Granted, but then bits are usually gathered into bytes by the hardware,
> so the issue doesn't concerns us programmers, in general.  That said,
> some hardware protocols transmit bytes in little endian bit order, while
> others transmit them in big endian bit order too :-)
>

a person does have to deal-with / define bit-ordering, if they are 
dealing with something like a Huffman encoder/decoder.

it doesn't necessarily have anything to do with the hardware bit 
ordering, but more, how bits are packed into the bytes for multi-bit values.

example:
start with high-bit, and emit high-bits first (big-big);
start with low-bit, and emit low-bits first (little-little).

other schemes are possible, but are a pain to encode/decode efficiently 
(usually they result from codecs which read/write 1 bit at a time), 
though often a transpose-table is a workable strategy.

conceptually, deflate transposes the Huffman codes (writing the MSB in 
LSB position), but this is partly because Huffman tends to require MSB 
first in-order to decode, and typically people don't really care about 
the numerical value of a Huffman code anyways.


>
>> personally, I prefer little endian, but don't really think it is a big
>> deal either.
>> […]
>> it is mostly just debatable if this would be worthwhile.
>
> Or if the debate is worthwhile :-)
>

could be.

I did experimentally throw together support for 64x64 blocks in my image 
codec, but thus far the results aren't really looking all that 
impressive (except one form which did really good on my test-patterns, 
but produces larger output for more normal images).

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

little-endian bob <bob@coolfone.comze.com> - 2012-11-15 13:45 -0800
  Re: little-endian JJ <jaejunks@glegooilma-swapit.com> - 2012-11-15 23:33 +0000
  Re: little-endian bob <bob@coolfone.comze.com> - 2012-11-16 10:38 -0800
    Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-16 23:32 +0100
      Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-16 21:17 -0600
        Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-17 10:26 +0100
          Re: little-endian "BartC" <bc@freeuk.com> - 2012-11-17 11:38 +0000
            Re: little-endian "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-17 13:56 +0100
              Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 11:58 -0600
            Re: little-endian Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-11-17 19:35 +0000
              Re: little-endian "BartC" <bc@freeuk.com> - 2012-11-17 19:50 +0000
          Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 11:30 -0600
            Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 09:28 +1300
              Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-17 14:48 -0600
                Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-17 16:22 -0600
                Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 15:17 +1300
                Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 09:13 +0100
                Re: little-endian Ian Collins <ian-news@hotmail.com> - 2012-11-18 21:33 +1300
                Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 10:15 +0100
                Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-18 03:03 -0600
                Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-18 10:29 +0100
                Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-18 12:50 -0600
  Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-22 04:49 -0800
    Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-23 15:22 +0100
      Re: little-endian pacman@kosh.dhis.org (Alan Curry) - 2012-11-25 19:39 +0000
        Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-26 12:01 +0100
          Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-26 14:02 +0100
            Re: little-endian Jongware <jongware@no-spam.plz> - 2012-11-26 15:34 +0100
              Re: little-endian "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-11-26 17:03 +0100
              Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-26 17:44 -0600
                Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-28 23:43 -0800
                Re: little-endian Robert Wessel <robertwessel2@yahoo.com> - 2012-11-29 22:46 -0600
          Re: little-endian BGB <cr88192@hotmail.com> - 2012-11-26 08:30 -0600
        Re: little-endian Robin Vowels <robin.vowels@gmail.com> - 2012-11-28 23:45 -0800

csiph-web