From: jawright AT my-dejanews DOT com Newsgroups: comp.os.msdos.djgpp Subject: Re: simple question :) Date: Fri, 09 Oct 1998 16:16:06 GMT Organization: Deja News - The Leader in Internet Discussion Lines: 46 Message-ID: <6vlcs7$n5s$1@nnrp1.dejanews.com> References: NNTP-Posting-Host: 206.166.249.100 X-Article-Creation-Date: Fri Oct 09 16:16:06 1998 GMT X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95) X-Http-Proxy: 1.1 x6.dejanews.com:80 (Squid/1.1.22) for client 206.166.249.100 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article , 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