Re: Byte ordering and array access
- From: "stathis gotsis" <stathisgotsis@xxxxxxxxxxx>
- Date: Sat, 11 Feb 2006 00:09:08 +0200
"Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx> wrote in message
news:dsithd$gt9$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
stathis gotsis wrote:
May i ask a question on this? Can the endian-ness of the processor
affect the "<<" shifting direction? From the replies i assume it does.
I need an example where this operator shifts to the right.
No, it does not affect shift "direction". It may help if you think of
shifts as repeated integer divisions/multiplications by 2 (that's how
Standard defines them -- they work on /values/ not representations).
Endianness only affect how values are stored in memory (their bit
representation, if you will). IOW, before performing the shift, C
program reads operand's representation, figures out the /value/,
performs shifting (i.e. division/multiplication), and if required
converts value back to representation, and stores it back.
I don't think you can construct the representation/endinanness
combination that will "reverse" shifts. Or, I'm not at my creative best
at the moment (a distinct possibility -- it's Friday evening, I should
be in a pub).
Well, yes there is a clear distinction between values and representations,
so my question was pointless anyway. But suppose we have 2-byte integers and
let int a=0xABCD. In one representation that could be: ABCD and in another:
DCBA. In terms of representations, one could say that in the first one "<<"
operator shifts left and in the second to the right. But that cannot happen
in the real world right?
Furthermore, let's take the OP. The program needs to evaluate the following
expression: ((unsigned int)byteArray[1] << 8). I assume that means that
byteArray[1] should move to the place of the next most significant byte in
the unsigned int word. So that shifting could be "left" or "right" depending
on endianness.
.
- Follow-Ups:
- Re: Byte ordering and array access
- From: Chris Torek
- Re: Byte ordering and array access
- From: pete
- 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
- Byte ordering and array access
- Prev by Date: Re: windows hates signal?
- Next by Date: Re: Windows/Linux optimization problem
- Previous by thread: Re: Byte ordering and array access
- Next by thread: Re: Byte ordering and array access
- Index(es):
Relevant Pages
|