On May 3, 5:45 pm, Charles Sullivan <cwsul...@triad.rr.comwrote:
On Sat, 03 May 2008 14:34:25 +0000, Willem wrote:
Charles wrote:
)
) Suppose I have this code:
)
) unsigned short svalue;
) unsigned char hibyte, lobyte;
)
) svalue = 0xABCD;
)
) hibyte = (svalue >8) & 0xFF;
) lobyte = svalue & 0xFF;
)
) Will this result in the values of hibyte and lobyte being 0xAB and
0xCD ) respectively, regardless of whether the platform is little or big
endian?
Of course it will. The shift operator doesn't care about endianess.
SaSW, Willem
Thanks Willem. That had been my understanding but some strange bug
reports from users got me wondering whether I was mistaken.
Then perhaps the bug lies somewhere else?
From ISO 9899:1999, 6.5.7:
The result of E1 >E2 is E1 right-shifted E2 bit positions.
If E1 has an unsigned type or if E1 has a signed type and a
nonnegative value, the value of the result is the integral part
of the quotient of E1 / 2^(E2) . If E1 has a signed type and a
negative value, the resulting value is implementation-deļ¬ned.
(int)(0xABCD / pow(2, 8)) == 0xAB (== 171)