Date: Mon, 5 Oct 1998 15:18:33 +0100 (BST) From: George Foot To: Craig Rothwell cc: djgpp AT delorie DOT com Subject: Re: converting 2 numbers into one In-Reply-To: <3618B080.ED38C4C@cdworld.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 5 Oct 1998, Craig Rothwell wrote: > how can I join 2 sets of binary > to make one? > > eg: > > turn '11111111' and '00000000' > (as 2 variables) > > into '1111111100000000'? (as one > variable) Shift the first one left by 8 bits, then add on the second: (a << 8) + b > A bit like using the Z80's HL > register, where you could treat > each variable seprate but also > as one big number. The 80x86 have that sort of system too. Assume `a' and `b' are global or static 32-bit integer variables: xorl %eax, %eax movb _a, %ah movb _b, %al movl %eax, _a That puts the bottom byte of `a' into the second byte of `a' and the bottom byte of `b' into the bottom byte of `a'. The rest of `a' is zeroed. -- 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