Re: Byte ordering and array access



"Chris Torek" <nospam@xxxxxxxxx> wrote in message
news:dslh8d02s77@xxxxxxxxxxxxxxxxxxxx
In article <dsj2u1$1o6f$1@xxxxxxxxxxxxxxxxxxx>
stathis gotsis <stathisgotsis@xxxxxxxxxxx> wrote:
Well, yes there is a clear distinction between values and
representations,
so my [original] question was pointless anyway.

Indeed. :-)

Thank you for taking the time to clarify these issues.

But suppose we have 2-byte integers [and standard 8-bit bytes]
and let int a=0xABCD. In one representation that could be: ABCD and
in another: DCBA.

This is getting close to the heart of the issue (with "endiannness"
being "the issue" in question).

"Endianness" is an artifact that arises when some entity takes a
whole -- such as the value 0xABCD -- and splits it into parts.
Here, you have allowed someone(s) to split it into two parts, "AB"
and "CD", and then scatter those two parts about your room, where
the cat can subsequently gnaw on them.

Well, in my previous example i allowed someone to split the 2-byte whole,
into 4-bit entities. I was wondering if that can happen in real-life
systems. Is the byte the atom (the smallest entity that cannot be further
split) in the context of endianness? If it is, then my example resides in
the field of imagination.

The question you should ask yourself is: who is this entity that
is splitting up your whole, and why are you giving him, her, or it
permission to do so? What will he/she/it do with the pieces? Who
or what will re-assemble them later, and will all the various
entities doing this splitting-up and re-assembling cooperate?

If *you* do the splitting-up yourself:

unsigned char split[4];
unsigned long value;

split[0] = (value >> 24) & 0xff;
split[1] = (value >> 16) & 0xff;
split[2] = (value >> 8) & 0xff;
split[3] = value & 0xff;

and *you* do the re-assembling later:

value = (unsigned long)split[0] << 24;
value |= (unsigned long)split[1] << 16;
value |= (unsigned long)split[2] << 8;
value |= (unsigned long)split[3];

will you co-operate with yourself? Will that guarantee that you
get the proper value back?

I think i will get the proper value back. In this example, C will hide any
implementation specific representation. I think with this expression:
(value >> n*8) & 0xff;
we get the (n+1) most significant byte, regardless of endianness. Is that
true? Can you show me of an example where C reveals endianness?

In terms of representations, one could say ...

In the Olden Daze, computer memory was stored in little magnetic
donuts called "cores" (see <http://en.wikipedia.org/wiki/Core_memory>).
You could actually point to the individual donuts holding each
individual bit in memory. Depending on the architecture (core
memory was often stored in "planes" for speed), it is quite reasonable
to expect that each bit of a single word would be stored in a
different circuit board in the computer. If you had an 18 or 36
bit word (those being common word sizes at the time), any given
value was stored in 18 or 36 different locations, none particularly
being "left" or "right" hand sided.
Even today, the actual bit layout on any given DRAM card "stick"
may be spread out, so that the chips holding your values may not
be particularly sort-able into "left" and "right" (they may be
mixed together, and/or "up" and "down"). You never notice because
you are unable -- at least without a logic probe -- to observe the
bits being split up and reassembled. A single entity (the memory
controller on the particular card) is responsible for the splitting-up
and re-assembling, and it always cooperates with itself.

That was food for thought but i think you went too low-level. Yes, memory
hides all internal implementation details, collects the 8-bits of a byte,
which maybe scattered on the chip, and gives the byte. I believe that the
real question is whether we can access pieces of data smaller than bytes in
a real memory? If we cannot then all possible processor-specific
endianness-es are the ways we can put two or more bytes in some memory
piece.


.



Relevant Pages

  • Re: Endianess
    ... > processor and the way it stores data in the memory subsystem. ... Endianness is a not so much a property of memory or CPU or I/O but of the ...
    (comp.sys.arm)
  • Re: portable issue of storing float point value in file
    ... write them to a file that keeps data in a format that is consistent ... that can be compiled to platforms of differing endianness without ... So--Instead of steaming through memory and dumping an image ... >> file or data transfer format is being used, the endianness problem need ...
    (microsoft.public.pocketpc.developer)
  • Re: portable issue of storing float point value in file
    ... on whatever the *file specification* dictates. ... the endianness if it is so required. ... load it into blocks of memory and use _swabto ... define it in the *file specification* no matter what ...
    (microsoft.public.pocketpc.developer)
  • Re: Mplayer: "Little-Endian"
    ... >> Bit shifts and rotates have nothing to do with the question of what ... > arranges multi-byte values in memory. ... that is what endianness is. ...
    (comp.os.linux.misc)
  • Re: A step by step discussion
    ... The researchers have presented stimuli ... Read In Search Of Memory to find out. ... representation of events is an assumption. ... understand the terminology of neuroscience, ...
    (comp.ai.philosophy)