Mail Archives: djgpp/1998/10/08/13:45:30
In article <6vcujm$2dt$1 AT antares DOT lu DOT erisoft DOT se>,
Martin DOT Stromberg AT lu DOT erisoft DOT se (Martin Stromberg) wrote:
> Craig Rothwell (craig AT cdworld DOT co DOT uk) wrote:
> : I have 2 numbers 12 (18) and
> : 212 (d4) and I want to convert
> : them into one number.
>
> : I know the number I want is 6356
> : but i don't know how to get it.
> : Can someone send me the right
> : code?
>
> How about (12 < 212 ? 6356 : 0)?
>
> Right,
>
> MartinS
>
Try this:
#include <stdio.h>
int main( void )
{
int a, b, c;
a = 12;
b = 18;
c = ( a << 16 ) + b;
printf("\nCombine 12 and 18 to get %d,\n", c);
printf(" or in hex 0x%04X\n, c);
}
This converts two bytes to one integer. Make sure you check endian
for the CPU you will use.
J-man
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -