Re: Byte ordering and array access
- From: Chris Torek <nospam@xxxxxxxxx>
- Date: 11 Feb 2006 20:25:49 GMT
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. :-)
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.
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?
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.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
.
- Follow-Ups:
- Re: Byte ordering and array access
- From: stathis gotsis
- 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
- Byte ordering and array access
- Prev by Date: Make a Makefile
- Next by Date: Re: pointer concepts
- Previous by thread: Re: Byte ordering and array access
- Next by thread: Re: Byte ordering and array access
- Index(es):
Relevant Pages
|