Beginning C question.
James Howard
jrh at mustang.dell.com
Tue Jul 24 14:09:14 AEST 1990
In article <10997 at chaph.usc.edu>, wsze at nunki.usc.edu (Wally "The Whale"
Sze) writes:
> I have a (beginning C) problem with a program I am working on. My
> compiler uses 16-bit ints, and I need to read some 32bit long ints
> from disk.
>
> (as a background, I wrote the same program for unix, and it worked
> fine when I used getw(), but on my home compiler it doesn't.. getw()
> returns only 16 bits).
>
> A way I can see to solve this is to read two ints from disk and
> concantenate them. But how do you concantenate ints? Say I have
> a = 0x20df and b = 0x3244, and want to get a long int 0x20df3244.
> If anyone can help, or if you can think of a better way to do this,
> please let me know by mail. Thank you.
This works on my system:
main()
{
short a=0x20df;
short b=0x3244;
int c;
c = (a<<16) + b;
printf("c = %x\n",c);
exit(0);
}
I used "short" because they're 16 bits on this machine, and int's are 32.
James Howard Dell Computer Corp. !'s:uunet!dell!mustang!jrh
(512) 343-3480 9505 Arboretum Blvd @'s:jrh at mustang.dell.com
Austin, TX 78759-7299
More information about the Comp.lang.c
mailing list