Re: Byte ordering and array access
- From: "stathis gotsis" <stathisgotsis@xxxxxxxxxxx>
- Date: Sun, 12 Feb 2006 17:39:02 +0200
"Chris Torek" <nospam@xxxxxxxxx> wrote in message
news:dslh8d02s77@xxxxxxxxxxxxxxxxxxxx
In article <dsj2u1$1o6f$1@xxxxxxxxxxxxxxxxxxx>representations,
stathis gotsis <stathisgotsis@xxxxxxxxxxx> wrote:
Well, yes there is a clear distinction between values and
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.
.
- Follow-Ups:
- Re: Byte ordering and array access
- From: Chris Torek
- Re: Byte ordering and array access
- From: Robin Haigh
- Re: Byte ordering and array access
- References:
- Byte ordering and array access
- From: Benjamin M. Stocks
- Re: Byte ordering and array access
- From: stathis gotsis
- Re: Byte ordering and array access
- From: Vladimir S. Oka
- Re: Byte ordering and array access
- From: stathis gotsis
- Re: Byte ordering and array access
- From: Chris Torek
- Byte ordering and array access
- Prev by Date: Re: Semantics of unary minus
- Next by Date: Re: How do I convert an int to binary form?
- Previous by thread: Re: Byte ordering and array access
- Next by thread: Re: Byte ordering and array access
- Index(es):
Relevant Pages
|