Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!udel!freezer!gdtltr From: gdtltr@freezer.it.udel.edu (Gary Duzan) Newsgroups: comp.lang.c Subject: Re: Beginning C question. Message-ID: <25440@nigel.udel.EDU> Date: 24 Jul 90 06:42:03 GMT References: <10997@chaph.usc.edu> <7703@uudell.dell.com> Sender: usenet@ee.udel.EDU Reply-To: gdtltr@freezer.it.udel.edu (Gary Duzan) Organization: Brain Dead Innovations, Inc. (BDI) Lines: 44 In article <7703@uudell.dell.com> jrh@mustang.dell.com (James Howard) writes: =>In article <10997@chaph.usc.edu>, wsze@nunki.usc.edu (Wally "The Whale" =>Sze) writes: =>> =>> 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. => Doesn't this depend on the implementation of putw and endianness? Since putw isn't standard (correct me if I'm wrong; it isn't in K&RII) it is difficult to say. I can easily see a case where c=a+(b<<16) might be right, or where you might have to deal with each byte. I doubt if this could be written portably. Of course, if portability isn't a concern, try Wally's solution and see if it works. Gary Duzan Time Lord Third Regeneration -- gdtltr@freezer.it.udel.edu _o_ -------------------------- _o_ [|o o|] If you can square, round, or cube a number, why not sphere it? [|o o|] |_O_| "Don't listen to me; I never do." -- Doctor Who |_O_|