Mail Archives: djgpp/1998/10/09/12:56:40
In article <Pine DOT OSF DOT 4 DOT 05 DOT 9810082028010 DOT 8766-100000 AT sable DOT ox DOT ac DOT uk>,
djgpp AT delorie DOT com wrote:
> On Tue, 6 Oct 1998 jwright AT adtran DOT com wrote:
>
> > a = 12;
> > b = 18;
> > c = ( a << 16 ) + b;
>
> You probably meant 8, not 16...
>
> > printf("\nCombine 12 and 18 to get %d,\n", c);
> > printf(" or in hex 0x%04X\n, c);
>
> .. otherwise the hex value won't show `a' at all (it's only 4
> digits long).
>
> > This converts two bytes to one integer. Make sure you check endian
> > for the CPU you will use.
>
> What has the endianness got to do with anything?
>
> --
> george DOT foot AT merton DOT oxford DOT ac DOT uk
>
> xu do tavla fo la lojban -- http://xiron.pc.helsinki.fi/lojban/lojban.html
>
>
You're right. I didn't "test" the code because it was so simple and
was thinking about a 16-bit result. Hence the >> 16. Thanks for the
correction.
Endianness of the source of the two bytes does matter. Assume that the
program is reading a hex dump file from a debugger memory dump. If the CPU
uses little endian (i.e. Intel TM), the lsb is lower in memory than the msb.
If the CPU uses big endian (i.e. Motorola TM), the msb is lower in memory than
the lsb. Recombining the data correctly depends on endianness. Maybe it was
more information than the original poster needed.
P.S. - I fixed my Deja-News account so all additional posts from me will have
a different e-mail address (Don't want spam at work).
jawright
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -